Advertisement

02.19.2008 at 06:31PM PST, ID: 23176386
[x]
Attachment Details

programmatically set checkbox in datagridview  to true/false

Asked by cnxmax in Microsoft Visual Basic.Net, .NET Framework 2.0

Tags: microsoft, vb.net 2.0, visual studio 2005

I have added a datagridview  (DGV) to a windows form.  I programmatically bind it to a data source.   I added a few DataGridViewCheckBoxColumn columns.  I loop through the columns of the DGV until I get to one of the checkbox columns.  I then loop through all rows.   For each Row / Column pair I query a database table using Row and Column information and retrieve a Boolean value.  I set the checkbox cell value to the Boolean value.  When the code finishes and the DGV is revealed, the bound cells are fine but no matter what I set the checkbox cells to (Boolean from datatable info, or 1, or TRUE) it always shows as an unchecked checkbox.  

DGV.Columns.Add(CreateCheckBoxColumn(sNewColumnName, sHeaderText))

Private Function CreateCheckBoxColumn(ByVal sNewColumnName, ByVal HeaderText) As DataGridViewCheckBoxColumn
Dim dataGridViewCheckBoxColumn1 As New DataGridViewCheckBoxColumn()
  dataGridViewCheckBoxColumn1.HeaderText = sHeaderText
  dataGridViewCheckBoxColumn1.Name = sNewColumnName
  dataGridViewCheckBoxColumn1.ThreeState = False
  dataGridViewCheckBoxColumn1.ValueType = GetType(Boolean)
  Return dataGridViewCheckBoxColumn1
End Function

For Each oColumn In Me.DGV.Columns
  If InStr(1, oColumn.Name, "res_", CompareMethod.Text) > 0 Then
     sHeaderText = oColumn.HeaderText
    For iLoop = 0 To Me.DGV.Rows.Count - 1
       sNameAddress = Me.DGV.Item("Fam_nameaddress", iLoop).Value
       bDBase_Value = Me.Tbl_FamilyTableAdapter.IsMemberResourceAvailable(sNameAddress, sHeaderText)
       Me.DGV.Item(oColumn.Index, iLoop).Value = bDBase_Value
    Next
  End If
Next
Start Free Trial
[+][-]02.19.2008 at 10:47PM PST, ID: 20935591

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Microsoft Visual Basic.Net, .NET Framework 2.0
Tags: microsoft, vb.net 2.0, visual studio 2005
Sign Up Now!
Solution Provided By: dampsey
Participating Experts: 2
Solution Grade: A
 
 
[+][-]02.20.2008 at 12:12AM PST, ID: 20935875

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]02.20.2008 at 07:16AM PST, ID: 20938529

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.20.2008 at 10:42PM PST, ID: 20945513

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628