Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Experts,

I have datagridview in windows forms. I wanted to bind the datatable. Also I want to have a checkbox for each. This is what I tried.
VB
Dim checkBoxColumn As New DataGridViewCheckBoxColumn()
     checkBoxColumn.HeaderText = "Select"
     checkBoxColumn.Width = 35
     checkBoxColumn.Name = "checkBoxColumn"
     dgvShow.Columns.Add(checkBoxColumn)
     dgvShow.Columns.Add("ICITEM", "Item")
     dgvShow.Columns.Add("ICDSC1", "Desc1")
     dgvShow.Columns.Add("ICDSC2", "Desc2")
     dgvShow.Columns.Add("ICDSC3", "Desc3")
     dgvShow.Columns.Add("ICTRLN", "Tireline")
     dgvShow.Columns.Add("I001001", "Manufacturer")

     For Each col As DataGridViewColumn In dgvShow.Columns
       col.Visible = col.HeaderText <> ""
       col.SortMode = DataGridViewColumnSortMode.NotSortable
     Next
     dgvShow.RowHeadersWidth = 24
     If Not ds Is Nothing Then
       For Each dr As DataRow In ds.Tables(0).Rows
         dgvShow.Rows.Add(dr("ICITEM"), dr("ICDSC1"), dr("ICDSC2"), dr("ICDSC3"), dr("ICTRLN"), dr("I001001"))
       Next
     End If


The values from the table are not binding properly if I add Checkbox column to grid. That means, value of DESC2 is getting binding to DESC1, value of DESC1 is binding to Item. I don't understand the error. Could someone help me with this please?
Posted

1 solution

Why not using the DataPropertyName of the column?
Then create a BindingSource of your ds.Tables(0) and bind that to your grid?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900