PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
VS 2008 Having trouble populating datagridviewer column. Please help-VBForums
Results 1 to 4 of 4

Thread: Having trouble populating datagridviewer column. Please help

  1. #1

    Thread Starter
    Addicted Member tgf-47's Avatar
    Join Date
    Feb 2010
    Location
    CapeTown, South Africa -34.01244,18.337415
    Posts
    209

    Question Having trouble populating datagridviewer column. Please help

    I have the following dataset and datatable:

    1 Code:
    1. Dim topics As New DataSet()
    2.     Public Function JT_PullData(ByVal TableName As String) As DataTable
    3.         If topics.Tables.Count >= 1 Then
    4.             topics.Clear()
    5.             names = Nothing
    6.             intSetArray = 0
    7.             i = 0
    8.         End If
    9.  
    10.         Dim conn As String = "Server=192.168.0.36;Port=3306;Database=wc;Uid=root;Pwd=123454321"
    11.         Dim cmd As String = "SELECT * FROM " & TableName
    12.         Dim ad As New MySql.Data.MySqlClient.MySqlDataAdapter(cmd, conn)
    13.  
    14.         ad.GetFillParameters()
    15.         ad.Fill(topics)
    16.  
    17.         Dim dr As DataRow
    18.         Dim dt As DataTable
    19.         dt = topics.Tables(0)
    20.         intSetArray = dt.Rows.Count
    21.         ReDim names(intSetArray, 4)
    22.  
    23.         For Each dr In dt.Rows
    24.             names(i, 1) = dr(1) 'Username
    25.             names(i, 2) = dr(2) 'Password
    26.             names(i, 3) = dr(3) 'Active
    27.             names(i, 4) = dr(4) 'Accesslevel
    28.             i += 1
    29.         Next
    30.         topics.Dispose()
    31.         JT_PullData = topics.Tables(0)
    32.     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:
    Name:  DATAGRID.JPG
Views: 79
Size:  33.9 KB

    I am supposed to set the dataset and then set the values that would be shown. (all by code )

  2. #2
    Fanatic Member
    Join Date
    Aug 2009
    Posts
    540

    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)
    Where I'm from we only have one bit of advice for new comers: "If you hear banjos, turn and run".


    VS 2008 .NetFW 2.0

  3. #3

    Thread Starter
    Addicted Member tgf-47's Avatar
    Join Date
    Feb 2010
    Location
    CapeTown, South Africa -34.01244,18.337415
    Posts
    209

    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?

  4. #4
    Fanatic Member
    Join Date
    Aug 2009
    Posts
    540

    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.
    Where I'm from we only have one bit of advice for new comers: "If you hear banjos, turn and run".


    VS 2008 .NetFW 2.0

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width