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

Vivek Thangaswamy 1 Reputation point
2021-06-29T12:05:44.3+00:00

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

110246-windowsusercontrol.png

Any solution in C#?

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,873 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Michael Taylor 51,346 Reputation points
    2021-06-29T13:50:06.173+00:00

    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.

    0 comments No comments

  2. Karen Payne MVP 35,386 Reputation points
    2021-07-02T21:24:24.777+00:00

    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

    0 comments No comments