1 Attachment(s)
Having trouble populating datagridviewer column. Please help
I have the following dataset and datatable:
1 Code:
Dim topics As New DataSet()
Public Function JT_PullData(ByVal TableName As String) As DataTable
If topics.Tables.Count >= 1 Then
topics.Clear()
names = Nothing
intSetArray = 0
i = 0
End If
Dim conn As String = "Server=192.168.0.36;Port=3306;Database=wc;Uid=root;Pwd=123454321"
Dim cmd As String = "SELECT * FROM " & TableName
Dim ad As New MySql.Data.MySqlClient.MySqlDataAdapter(cmd, conn)
ad.GetFillParameters()
ad.Fill(topics)
Dim dr As DataRow
Dim dt As DataTable
dt = topics.Tables(0)
intSetArray = dt.Rows.Count
ReDim names(intSetArray, 4)
For Each dr In dt.Rows
names(i, 1) = dr(1) 'Username
names(i, 2) = dr(2) 'Password
names(i, 3) = dr(3) 'Active
names(i, 4) = dr(4) 'Accesslevel
i += 1
Next
topics.Dispose()
JT_PullData = topics.Tables(0)
End Function
Now I have a column in my DataGridViewer that is a dropdown list. This list is to be populated by the datasel above.
I can't seem to get it to work. Help me, please
Here is an image:
Attachment 77877
I am supposed to set the dataset and then set the values that would be shown. (all by code )
Re: Having trouble populating datagridviewer column. Please help
Each of those you see are properties in code.
DataGridView1.Datasource = dt (if for some reason you can't set a datatable as a source, add the table to a data set and then use the dataset as a source)
DataGridView1.DisplayMember = "Name of your Column"
DataGridView1.ValueMember = "Name of your Column" (this is usually a PK or ID type field)
Re: Having trouble populating datagridviewer column. Please help
I do get
DataGridView1.Datasource
But I cant find the DisplayMember and ValueMember Properties for some weird reason. Any Ideas?
Re: Having trouble populating datagridviewer column. Please help
That's because I was wrong assuming the display and value members were properties of the columns of your data grid view. They're actually properties of the comboboxcolumn itself.
Code:
Dim comboboxcol As DataGridViewComboBoxColumn = Me.DataGridView1.Columns("NameOfCol")
comboboxcol.DisplayMember =
comboboxcol.ValueMember =
You could always add the column in by code rather through the designer.