使用DataGridView.AutoGenerateColumns = True时,绑定对象的布尔属性更新正常,但不是手动添加列时。价值观仍然是错误的。手动生成的DataGridViewCheckBoxColumn不更新绑定对象
添加DataGridViewCheckBoxColumn时是否需要设置一些参数?似乎不足以设置.DataPropertyName。
我看到它有一些像.TrueValue,.FalseValue等其他属性,但不知道它们是什么?
或者我是否需要编写一些类型的自定义CellFormatting/CellValidating事件?
编辑:
<Extension()> _
Public Sub AddCheckBoxColumn(ByVal dgv As DataGridView, ByVal propertyName As String, ByVal colName As String, ByVal fillWeight As Integer)
Dim col As New DataGridViewCheckBoxColumn(False)
col.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
col.HeaderText = colName
col.Name = colName
col.Width = fillWeight
col.DataPropertyName = propertyName
dgv.Columns.Add(col)
End Sub
如果您在后面的代码中手动添加标记和代码,您可以显示标记和代码吗? – 2011-05-22 22:08:05
我不熟悉“后面的代码”这个表达方式吗?这是一个Windows窗体项目。但在上面添加了一些代码。 – bretddog 2011-05-22 22:16:41
在添加列后,您是否在网格上运行DataBind()? – 2011-05-22 22:20:08