Hi,
Here I am, wondering what I'm missing in my code.
Maybe I should just ask if there is a problem or a must-do-code that have to be present when one tries to create a datagridview in runtime and then tries to access the columns. I always gets zero for the columns count even thought I can see the information displayed.
If this is true, then please forget the rest of the post, if not, them be patient while reading the rest of this post.
Background:
It's not easy to explain, I'm trying to parametrize some process, and to do this I'm retrieving a list of records from the database that contains "metadata" of different information.
One example, take a list of groups, the user selects one group and a list of possible things to do with that group is displayed in the options panel (the list of options comes from the database), if the user selects one option, from the database I retrieve the suboptions, and they get populate in datagridviews inside TabPages. Each datagridview, tabpage and button is create at runtime.
List of Groups
Admin
Power User
Options
Group Privileges
Group Father
[highlight]Assign[/highlight]
Delete User
[highlight]Remove[/highlight]
Create user
Modify User
My problem is, after creating the datagridview the columns count is always zero. In the screen I see the information and is correct, but I cannot access the columns through code.
I would appreciate any help.
Thanks for the help.
David
Here I am, wondering what I'm missing in my code.
Maybe I should just ask if there is a problem or a must-do-code that have to be present when one tries to create a datagridview in runtime and then tries to access the columns. I always gets zero for the columns count even thought I can see the information displayed.
Code:
Dim DGVLista As DataGridView
DGVLista = New DataGridView()
da2.Fill(ds2, "list")
DGVLista.DataSource = ds2
DGVLista.DataMember = "list"
If DGVLista.Columns.Count > 0 Then [red][b]always zero[/b][/red]
DGVLista.Columns(0).Visible = False
End If
If this is true, then please forget the rest of the post, if not, them be patient while reading the rest of this post.
Background:
It's not easy to explain, I'm trying to parametrize some process, and to do this I'm retrieving a list of records from the database that contains "metadata" of different information.
One example, take a list of groups, the user selects one group and a list of possible things to do with that group is displayed in the options panel (the list of options comes from the database), if the user selects one option, from the database I retrieve the suboptions, and they get populate in datagridviews inside TabPages. Each datagridview, tabpage and button is create at runtime.
List of Groups
Admin
Power User
Options
Group Privileges
Group Father
[highlight]Assign[/highlight]
Delete User
[highlight]Remove[/highlight]
Create user
Modify User
My problem is, after creating the datagridview the columns count is always zero. In the screen I see the information and is correct, but I cannot access the columns through code.
I would appreciate any help.
Code:
Dim ds As New DataSet
Dim ds2 As New DataSet
Dim da As OleDb.OleDbDataAdapter
Dim da2 As OleDb.OleDbDataAdapter
Dim Tab As TabPage
Dim Boton As Button
Dim DGVLista As DataGridView
da = New OleDb.OleDbDataAdapter("exec USUARIOS.dbo.OPCIONXUSUARIO_select_opcion_tab_sp " & DGVOpciones.Item("PKOPCION", DGVOpciones.CurrentRow.Index).Value, Conexion)
da.Fill(ds, "tab")
Dim QUERY_BOTON(ds.Tables("tab").Rows.Count) As String
TCListas.TabPages.Clear()
Var.Indice = 0
While Var.Indice < ds.Tables("tab").Rows.Count
Tab = New TabPage
Tab.Text = ds.Tables("tab").Rows(Var.Indice).Item("PROCESO")
If ds.Tables("tab").Rows(Var.Indice).Item("QUERY_LISTA") IsNot DBNull.Value Then
DGVLista = New DataGridView()
da2 = New OleDb.OleDbDataAdapter(ds.Tables("tab").Rows(Var.Indice).Item("QUERY_LISTA") & " " & PK & ", " & Var.Sesion.PKCICLO & ", " & Var.Sesion.PKUSUARIO, Conexion)
da2.Fill(ds2, "listas" & Var.Indice)
DGVLista.AutoGenerateColumns = True
DGVLista.DataSource = ds2
DGVLista.DataMember = "listas" & Var.Indice
DGVLista.ReadOnly = True
DGVLista.AllowUserToResizeColumns = True
DGVLista.AllowUserToOrderColumns = True
DGVLista.AlternatingRowsDefaultCellStyle.BackColor = Color.Beige
DGVLista.RowHeadersVisible = False
DGVLista.MultiSelect = False
DGVLista.SelectionMode = DataGridViewSelectionMode.FullRowSelect
DGVLista.BorderStyle = BorderStyle.Fixed3D
DGVLista.Anchor = AnchorStyles.Bottom + AnchorStyles.Left + AnchorStyles.Right + AnchorStyles.Top
DGVLista.Width = 190
If ds.Tables("tab").Rows(Var.Indice).Item("QUERY_BOTON") Is DBNull.Value Then
DGVLista.Height = 90
Else
DGVLista.Height = 60
End If
DGVLista.Left = 6
DGVLista.Top = 6
If DGVLista.Columns.Count > 0 Then [red][b]always zero[/b]
DGVLista.Columns(0).Visible = False
End If
Tab.Controls.Add(DGVLista)
End If
ds2.Dispose()
If ds.Tables("tab").Rows(Var.Indice).Item("QUERY_BOTON") IsNot DBNull.Value Then
Boton = New Button
Boton.Text = ds.Tables("tab").Rows(Var.Indice).Item("BOTON")
Boton.Width = 136
Boton.Height = 23
Boton.Left = 45
Boton.Top = 70
Boton.Anchor = AnchorStyles.Bottom
Tab.Controls.Add(Boton)
QUERY_BOTON(Var.Indice) = ds.Tables("tab").Rows(Var.Indice).Item("QUERY_BOTON")
End If
Me.TCListas.TabPages.Add(Tab)
Var.Indice = Var.Indice + 1
End While
Thanks for the help.
David