I have a strange issue. Basically I have a datagridview and a button. When I click this button it checks all rows for column 1s value - the checkbox column. It then sets it to true / false depending on what it currently is.
Thats all fine.
But then, I have another button to do something with these rows that are ticked. I click it and it only ever identifies the first row as being ticked. The rest are apparently null now..?
So, how can I programmtically set the value of a checkbox column in a datagrid view and then read it again cause Im apparently way off the mark based on my results.
This sets the tick boxs and I can see them, untick them manually etc.
foreach (DataGridViewRow row in dgv.Rows)
{
var ch1 = new DataGridViewCheckBoxCell();
ch1 = (DataGridViewCheckBoxCell)row.Cells[0];
if (ch1.Value == null)
ch1.Value = false;
switch (ch1.Value.ToString())
{
case "True":
ch1.Value = false;
break;
case "False":
ch1.Value = true;
break;
}
}
Then the next button to check values is just finding nulls
foreach (DataGridViewRow row in rows)
{
var ch1 = new DataGridViewCheckBoxCell();
ch1 = (DataGridViewCheckBoxCell)row.Cells[0];
if (ch1.Value == null)
ch1.Value = false;
switch (ch1.Value.ToString())
{
case "True":
ch1.Value = true;
break;
case "False":
ch1.Value = false;
break;
}
var val = row.Cells["EbayListingID"].Value.ToString();
if (ch1.Value.ToString() == "true") continue;
var listing = dsEntities.EbayListings.First(x => x.EbayListingID.ToString() == val);
SubmitListingForReview(listing, false);
}