I have some records from a database displayed in a datagridview for the use to view and select data. I needed a way for users to select individual records for exporting the data into a formatted PDF document so I set up a CheckBoxCollumn. My Database and subsequent datagridviews are set up in tandem with one containing basic client information and the other the accounts associated with them. As I'm using the gridviews in tandem when a client is selected on the associate records show in the gridview. This means that if the user wants more than one clients records selected than they're unable to. To solve this problem I want to log what records have been checked and then when the PDF is generated it pulls the data from the records. My problem is with identifying which records are checked.
private void Accounts_DataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
foreach (DataGridViewRow row in accounts_DataGridView.Rows)
{
DataGridViewCheckBoxCell cell = row.Cells[0] as DataGridViewCheckBoxCell;
if (cell.Value == cell.TrueValue)
{
MessageBox.Show("its checked");
}
}
}
}
This is the code that I currently have. The event handling functions correctly but the value always returns null.
I have faced the same issue in the past and I never got it working with the
TrueValueproperty.Instead, I used the
cell.Valueproperty like below and I was able to continue my project without diving into the events ofDataGridViewthat may be happening in the background.