Link to home
Start Free TrialLog in
Avatar of SGUDAPAT
SGUDAPATFlag for United States of America

asked on

Help-Adding check boxes to data grid control and accessing them

Hi
I need to add to check box controls to the data grid view, when I am retreiving data from database, i.e I need to loop the check boxes such that how many ever rows I get from the database, these rows should have check boxes beside them.
I tried writing some code which is below, I was able to get check boxes, but I am not able to access them, i.e I am not able to check them, I also want something like SelectAll and UnSelectAll buttons, when I click on the SelectAll button, it should check all the check boxes and when I click UnselectAll button, it should be able to uncheck all check boxes.

And also one more thing, I don't why it is adding an extra empty row in the data gird view, how do I  avoid that.
If GetDataSet(DS, sSQL) Then
            With DS.Tables("Table")
                count = .Rows.Count
                If .Rows.Count > 0 Then
                    'Populated the DataGridView with the data from the dataset
                    RDGVW.DataSource = DS.Tables("Table")
                    With Chkbx
                        .Name = "check"
                        .HeaderText = "Status"
                     End With
                    RDGVW.Columns.Add(Chkbx)
                End If
            End With
        End If

Open in new window

code.doc
Avatar of ptakja
ptakja
Flag of United States of America image

I am not sure about the MS Gridview Control, since I use Infragistics almost exclusively for grid rendering, but what if you add a column to your DataTable object BEFORE you bind it to the grid view? Set the data type of the column to "Bit" or "Boolean". Some grids will automatically render a bit/boolean data type as a checkbox.

To check all/clear all, you simply would then loop through the grid and for each row set the value of that cell to 0.

Also, looking at your code, there is not enough there to determine why you get an extra row.
Avatar of SGUDAPAT

ASKER

Hi
Thank you for the response, how do I add the data table to data grid view?

I did something like
dt.Columns.Add("NO")
dt.Columns.Add("LINE")
and added the columns to data table, but how do I add the check boxes to the data table and and them to the data grid........ I am begginner in Vb.Net, please explain it to me.
ASKER CERTIFIED SOLUTION
Avatar of ptakja
ptakja
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Solution has been posted. User can revisit to get answer at another time.