带有复选框列的Datagridview值不绑定 [英] Datagridview values with checkbox column doesn't bind

查看:61
本文介绍了带有复选框列的Datagridview值不绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Experts,



我在windows窗体中有datagridview。我想绑定数据表。另外,我希望每个都有一个复选框。这是我试过的。

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.

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





如果我将Checkbox列添加到网格中,则表中的值无法正确绑定。这意味着,DESC2的值正在与DESC1绑定,DESC1的值绑定到Item。我不明白这个错误。有人可以帮我吗?



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?

推荐答案

为什么不使用该列的DataPropertyName?

然后创建你的ds的BindingSource。表(0)并将其绑定到您的网格?
Why not using the DataPropertyName of the column?
Then create a BindingSource of your ds.Tables(0) and bind that to your grid?


这篇关于带有复选框列的Datagridview值不绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆