Click here to Skip to main content
15,851,387 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a data grid view in which I have a check box.
And I have a database table in which one column name is select which is boolean type. Im accessing the table value in data set´, if select value is true I want to checked the check box automatically. Please help.
Updated 11-Jul-11 0:13am

I have done the similar thing in windows app Gridview's click event,i want to access grid's selected row's 9th cell value which is a check box,try this and make your logic

string valuechk = dataGridView1.CurrentRow.Cells[9].Value.ToString ();
// int value = int.Parse(valuechk);
 bool chkvalue = Convert.ToBoolean(valuechk);
 //if (dataGridView1.CurrentRow.Cells[8].Value == "0")
 if(chkvalue ==false)
      assignchk.Checked = false;//assignchk is a check box on form
      assignchk.Checked = true;
Share this answer
Share this answer
advancedansh 11-Jul-11 6:21am    
i already check that link
void fill()

int i;
DataSet ds = new DataSet();
string str = "select * from user1 ";

adap = new SqlDataAdapter(str, con);
adap.Fill(ds, "user1");

dataGridView1.AutoGenerateColumns = false;
dataGridView1.DataSource = ds.Tables["user1"];
dataGridView1.Columns["FirstName"].DataPropertyName = "FirstName";
dataGridView1.Columns["LastName"].DataPropertyName = "LastName";
dataGridView1.Columns["username"].DataPropertyName = "username";
dataGridView1.Columns["password"].DataPropertyName = "password";

int cou =ds.Tables[0].Rows.Count;
for (i = 0; i < cou; i++)

bool chk = Convert.ToBoolean(ds.Tables[0].Rows[i][4]);
if (chk == true)

dataGridView1.Columns["checkbox"].DataPropertyName = "checkbox";
pls help me in this respect

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