?
Solved

Getting Value of Checkbox in a Datagridview

Posted on 2012-08-30
3
Medium Priority
?
624 Views
Last Modified: 2012-08-30
Good Morning All,

I'm using vb.net 2008.  I'm loading a datagridview with records from a database.  In the datagridview i have some checkboxes.  Whenever I load the data, many of the checkbox columns are checked.  When I try to retrieve the value to see if it's checked I always get "nothing".  Here is what I'm doing:

This just loads the grid.  I have more columns but I'm sure you get the point.

Dim dsData As DataSet = .GetData()
For Each dt In dsData.Tables
      For Each dr In dt.Rows
           datagrid.rows.add()
           With datagrid.rows(intRow)
                 .Cells("field1").Value = dr.Item("field1").ToString 'Checkbox column
                 intRow += 1
           End With
      Next
Next

Then I'm doing this to get the value of the checkbox:
 
I'm doing this in a sub after the grid has been loaded.

Dim chkboxEval As DataGridViewCheckBoxCell = New DataGridViewCheckBoxCell(dgv.CurrentCellAddress.X = 4)
chkboxEval = CType(dgv.Rows(intRow).Cells(4), DataGridViewCheckBoxCell)
 
If chkboxEval.Value = True Then
     dgv.Rows(intRow).Cells("Field1").ReadOnly = True
     dgv.Rows(intRow).Cells("Field2").ReadOnly = True
Else
     dgv.Rows(intRow).Cells("Field1").ReadOnly = True
     dgv.Rows(intRow).Cells("Field2").ReadOnly = True
End If

I've even tried, If chkboxE.Value  = chkboxE.TrueValue ....

The value of chkboxEval.value (even when checked) = Nothing.

Any ideas what I'm doing wrong or not doing that I should be?

Thanks in advance!

Jim
0
Comment
Question by:transstates
  • 2
3 Comments
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 2000 total points
ID: 38350560
Have you tried

dgv.Rows(intRow).Cells(4).Value

?

What does it return?
0
 

Author Comment

by:transstates
ID: 38350912
It has the value "true".  I think this might be it... brb

Ok, this works but when the sub is done and I look at the grid, while the row is checked the code to make it read only is not working correctly.  hmmm..

I see it now...  I was runing code after the fact that was messing with the rights of the grid.

Thank you!
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38351004
That .Value should work for the checkbox. What code do you have to make it readonly?
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month16 days, 12 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question