开发者

Manually generated DataGridViewCheckBoxColumn not updating bound object

When using DataGridView.AutoGenerateColumns = True, the boolean property of bound object is updated fine, but not when I add columns manually. Values remain False.

Are there some parameters I need to set when adding the DataGridViewCheckBoxColumn? It seems not to be sufficient to set the .DataPropertyName.

I see it has some other properties like .TrueValue, .FalseValue etc, but not sure what they are for?

Or do I need to write some type of custom CellFormatting/CellValidating events?

EDIT: I add column by extension method:

    <Extension()> _
Public Sub AddCheckBoxColumn(ByVal dgv As DataGridView, ByVal propertyName As String, ByVal colName As String, ByVal fillWeight As Integer)
    Dim col As New DataGridViewCheckBoxCo开发者_运维问答lumn(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


Maybe you misspelled the name of the bound field? It should work as long as your data column is of boolean type.

If not, TrueValue would express value to set when checkbox is checked, and FalseValue would express value when checkbox is not set, for example you could map strings "Checked" and "Unchecked" to field of type string.

  1. Does reading from the field work correctly?
  2. Can you check the checkbox, or It stays unchecked when you click it?


Found my mistake. Had an incomplete extension method with the same name in a different library. So it did not use the method I was changing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜