question

VivekThangaswamy-2852 avatar image
0 Votes"
VivekThangaswamy-2852 asked karenpayneoregon answered

Unable to read Checkbox from : DataGridView User Controls in Windows Forms

Unable to read Checkbox from : DataGridView User Controls in Windows Forms

110246-windowsusercontrol.png



Any solution in C#?

windows-forms
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi VivekThangaswamy-2852,
In order to solve the problem more accurately and quickly, please provide the relevant code and the specific problem encountered.
Best Regards,
Daniel Zhang

0 Votes 0 ·
cooldadtx avatar image
0 Votes"
cooldadtx answered

It works like it does for other cells. You didn't post any code so we cannot see what you've tried nor what you're trying to do but if you're data binding then you shouldn't need to read it directly anyway. DGV will bind the cell value to the boolean you're backing it with.

But if you need to read it then you'll go to the cell that has the checkbox and read the Value property, which is an object. Cast it to a boolean (assuming only true/false values). Alternative you can cast the cell to the DataGridViewCheckBoxCell if you need something more.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

karenpayneoregon avatar image
0 Votes"
karenpayneoregon answered

Discarding whatever you are talking about a UserControl, the following repository shows

  • How to get checked/unchecked values for the current row and all rows

  • Using a numeric column

  • Properly working with a DataGridViewComboBox

Fine points, a DataGridView can be used unbound or setup to load from a data source, in this case a SQL-Server database tables are used. Using a DataGridView where the data source is not set is simply in 99 percent of cases is the wrong path to take.

Couple of screenshots

The Check button shows how to get all rows checked/unchecked while in the following method shows getting the checked/unchecked value and other properties.

111443-datagridview.png




datagridview.png (30.7 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.