Hi, I have a gridview with checkboxes in the 3rd column. I am trying to work out when they are selected. I have the following code:
foreach (GridViewRowInfo dr in gvMovies.Rows) if (dr.Cells[2].Value = true) MessageBox.Show("Row " + dr.Index + " selected");
|
I get the following error: Cannot implicitly convert type 'object' to 'bool'. An explicit conversion exists (are you missing a cast?) I have tried the following but nothing has worked:
foreach (GridViewRowInfo dr in gvMovies.Rows) if ((bool)dr.Cells[2].Value = true) MessageBox.Show("Row " + dr.Index + " selected");
|
foreach (GridViewRowInfo dr in gvMovies.Rows) if (Convert.ToBoolean(dr.Cells[2].Value) = true) MessageBox.Show(dr.Cells[2].Value + " Rows " + dr.Index + " selected");
|
Thanks for any replies
Jay
Sam HobbsPosted Jan 31, 2011, 2:16 AM
Jay WebsterPosted Jan 31, 2011, 2:07 AM
foreach (GridViewRowInfo dr in gvMovies.Rows)
if (dr.Cells[2].Value == true) MessageBox.Show("Row " + dr.Index + " selected");
I feel silly!
Sorry I forgot to mention I am using "Telerik Winform Controls".
Thanks for all the help!
Suthish NairPosted Jan 31, 2011, 1:05 AM
theLizardPosted Jan 30, 2011, 8:19 PM
I am assuming that you have assigned a check box to the cell you want to evaluate as Boolean, if so the first thing you need to do is to cast the object in the cell back to a checkbox eg
{
CheckBox cb = dr.Cells[2];
if(cb.Checked)
.......
// or maybe this ---- if(((CheckBox cb=dr.Cells[2]).Checked) == true)
}
But I am ONLY guessing at this point.
Sam HobbsPosted Jan 30, 2011, 6:38 PM