Help With Datagrid Checkboxes with DataGridBoolColumn

asn1981

Active member
Joined
Mar 15, 2005
Messages
38
Programming Experience
Beginner
i am trying to add a checkbox to a datagrid on a windows form
the checkbox would allow the user to specify particular records that need to be worked with in the next form

to create the checkboxes I added a column to the dataset which obv doesnt contain anything
I then created a DataGridBoolColumn for the check boxes

When the form is loaded everything appears fine in the datagrid with the checkboxes appearing unchecked but users are not able to check or uncheck the created checkboxes

any idea why this would happen, my code is below, thanks inadvance.


'clear all styles - for when searched are retried
dgResults.TableStyles.Clear()

'need to add this new column for the checkbox
Dim CheckBox As New Data.DataColumn
With CheckBox
.DataType = GetType(System.Boolean)
.DefaultValue = False
'.AllowDBNull = False
.ReadOnly = False
.ColumnName = "CheckBox"
End With

ds.Tables(0).Columns.Add(CheckBox)

'create a Grid Table Style. Map it to the "Customers" Table.
Dim aGridTableStyle As New DataGridTableStyle
aGridTableStyle.MappingName = sTableName

'create GridColumnStyle objects for the grid columns
Dim aCol1 As New DataGridTextBoxColumn
Dim aCol2 As New DataGridTextBoxColumn
Dim aCol3 As New DataGridTextBoxColumn
Dim aCol4 As New DataGridTextBoxColumn
Dim aCol5 As New DataGridTextBoxColumn
Dim aCol6 As New DataGridTextBoxColumn
Dim aCol7 As New DataGridBoolColumn

With aCol1
.MappingName = "employeefirstname"
.HeaderText = "Firstname"
.Width = 75
.Alignment = HorizontalAlignment.Left
.TextBox.Enabled = False
End With
With aCol2
.MappingName = "employeesurname"
.HeaderText = "Surname"
.Width = 75
.Alignment = HorizontalAlignment.Left
.TextBox.Enabled = False
End With
With aCol3
.MappingName = "jobtitle"
.HeaderText = "Job Title"
.Width = 100
.Alignment = HorizontalAlignment.Left
.NullText = ""
.TextBox.Enabled = True
'.Format = "yyyy-MM-dd"
End With
With aCol4
.MappingName = "department"
.HeaderText = "Department"
.Width = 100
.Alignment = HorizontalAlignment.Left
.NullText = ""
.TextBox.Enabled = True
End With
With aCol5
.MappingName = "employeelocation"
.HeaderText = "Location"
.Width = 80
.Alignment = HorizontalAlignment.Left
.TextBox.Enabled = False
End With
With aCol6
.MappingName = "employeeemail"
.HeaderText = "Email"
.Width = 195
.Alignment = HorizontalAlignment.Left
.TextBox.Enabled = False
End With

'checkbox
With aCol7
.MappingName = "CheckBox"
.HeaderText = "Select"
.TrueValue = True
.FalseValue = False
.AllowNull = False
.NullValue = False
.ReadOnly = False
.Width = 40
End With

'add the GridColumnStyles to the DataGrid's Column Styles collection. can order cols at this point
With aGridTableStyle.GridColumnStyles
.Add(aCol1)
.Add(aCol2)
.Add(aCol3)
.Add(aCol4)
.Add(aCol5)
.Add(aCol6)
.Add(aCol7)
End With

'add the GridColumnStyles to the aGridTableStyle.
dgResults.TableStyles.Add(aGridTableStyle)

' bBind the DataGrid to the DataSet. Expand and navigate to first row.
If ds.Tables(0).Rows.Count > 0 Then
With dgResults
.DataSource = ds.Tables(0)
End With
End If
 
Back
Top