I want to check if my datagridview value stored in column[2] is empty or null.
How can I access datagridview column?
string[] row = new string[]
{
Convert.ToString(dataReader[0]),
Convert.ToString(dataReader[1]),
Convert.ToString(dataReader[2]),
Convert.ToString(dataReader[3])
};
dataGridView1.Rows.Add(row);
whit this code you can access column from your DataGridView
foreach (DataGridViewColumn col in dataGridView1.Columns)
but for checking null values you should check the cells not the column, so just add another for to count your rows and check every cells of your specific column
your code will be like this:
for (int colCounter=0 ; colCounter<dataGridView1.Columns.Count; colCounter++)
for(int rowCounter=0 ; rowCounter<dataGridView1.Rows.Count ; rowCounter++)
if(DataGridView1.Rows[rowCounter].Cells[colCounter].Value.tostring()==null)
//your code
I think you need to use a loop to add those data in your datagridview
like this:
foreach(var data in row)
{
dataGridView1.Rows.Add(data);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.