Automatically checked for dynamic check box in datagrid view
Hi,
I have a checkbox that is dynamically added to the datagridview.I would like to have the checked box checked automatically when it is created.I do not want to loop the datagridview to get the checked box checked which work like this:
Code:
this.dataGridView1.Rows[RowIndex].Cells[ColumnIndex].Value = true
I find no ways to do this.Below is my coding:
Code:
DataGridView1.Columns.Add(CreateCheckBoxColumn)
Private Function CreateCheckBoxColumn() As DataGridViewCheckBoxColumn
Dim dataGridViewCheckBoxColumn1 _
As New DataGridViewCheckBoxColumn()
dataGridViewCheckBoxColumn1.HeaderText = "Insert"
dataGridViewCheckBoxColumn1.TrueValue = True
dataGridViewCheckBoxColumn1.FalseValue = False
dataGridViewCheckBoxColumn1.IndeterminateValue = 3
dataGridViewCheckBoxColumn1.ThreeState = True
Return dataGridViewCheckBoxColumn1
Return dataGridViewCheckBoxColumn1
End Function
Does anyone has idea on dooing this?
Re: Automatically checked for dynamic check box in datagrid view
Use RowsAdded eveent to set the checkBoxCOlumns value to true
Code:
Private Sub DataGridView1_RowsAdded(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewRowsAddedEventArgs) Handles DataGridView1.RowsAdded
DataGridView1.Rows(e.RowIndex).Cells(DataGridView1.Columns("Insert").Index).Value = True
End Sub
Also add this to initialization of checkboxColumn
Code:
dataGridViewCheckBoxColumn1.Name = "Insert"
Re: Automatically checked for dynamic check box in datagrid view