Click here to Skip to main content
15,896,429 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I am trying to add a checkbox column to a DataGridView in a simple window forms application.

I am pulling back some data from a database using ADO.NET, putting into a datatable, and then setting the datagridview datasource to the datatable. I then want to add a checkbox column as the second column. So far I have this code that seems to work:
Posted
Comments
Sander Rossel 21-Apr-11 1:45am    
Where is the code? And if it seems to work then what is the question?

1 solution

MyDataContext DC = new MyDataContext();

var DS = from a in DC.MyTable select a;

DataTable DT = new DataTable();
DT.Columns.Add("Check", typeof(bool));
DT.Columns.Add("Value", typeof(string));

foreach (var item in DS)
{
    DataRow DR = DT.NewRow();
    DR[0] = false;
    DR[1] = item.Value;
    DT.Rows.Add(DR);
}

MyGridView.DataSource = DT;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900