In my code below i can click on two columns of a datagrid cells that contain buttons, it works great, how ever some of the row cells contain no data, how can i adapt the bellow to ignore nulls and do nothing if the cell button is clicked?
private void appsDataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 0)
{
//perform function here on click but if null ignore
salesDataGridView.Rows[newIndex].Cells[0].Value = appsDataGridView.Rows[e.RowIndex].Cells[0].Value;
}
else if (e.ColumnIndex == 1)
{
//perform function here on click but if null ignore
salesDataGridView.Rows[newIndex].Cells[0].Value = appsDataGridView.Rows[e.RowIndex].Cells[1].Value;
}
}

1 answers
Try:
answered 5 months ago by:
11603
11603
I'v edited my original attempt as it will be the Value property that will be null if there's no data, not its string representation.
495
Thanks vulpes, i've edited my question at the top as i'm copying data from one datagrid to another - but sometimes in datagrid1 there may be a null button, if that's the case i don't want a blank line copying to datagrid2, the above code still copies over a blank line?
11603
Doh, I've got the row and column indices the wrong way around in the appsDataGridView indexer, which may explain why it's not working properly. Try it again now I've re-edited it.
495
Yes it works a treat now - nice one Thanks, much appreciated.