Well... um.
Let's look at this logically:
foreach (DataGridViewRow row in form3.dbMetName.Rows)
{
...
}
Looks at every row
foreach (DataGridViewColumn col in form3.dbMetName.Columns)
{
...
}
Looks at every column in every row.
And then:
if (row.Cells[col.Name].Value != null)
dbSumMetName.Rows[row.Index].Cells[col.Name].Value = row.Cells[col.Name].Value;
So...what value are you putting in a cell if the value you don't want to put in the cell is null?
Nothing at all.
Otherwise known as
null
...so if the "new" value is null, you leave the old, null value...
Perhaps, you want something like this:
foreach (DataGridViewRow row in form3.dbMetName.Rows)
{
foreach (DataGridViewColumn col in form3.dbMetName.Columns)
{
if (row.Cells[col.Name].Value != null)
{
dbSumMetName.Rows[row.Index].Cells[col.Name].Value = row.Cells[col.Name].Value;
}
else
{
dbSumMetName.Rows[row.Index].Cells[col.Name].Value = "????";
}
}
}
"how to remove 1 whole row if let say there are two column and two column has no value. some sort like this code"
DataGridView1.Rows.Remove(_row);
Well...first thing is: you can't use foreach. It would require modifying the collection, and that is not allowed within a foreach.
So, if you want to get rid of the whole row if all it's columns are empty:
for (int i = form3.dbMetName.Rows.Count - 1; i >= 0; i--)
{
bool isBlank = true;
DataGridViewRow row = form3.dbMetName.Rows[i];
foreach (DataGridViewCell cell in row.Cells)
{
if (cell.Value != null && cell.Value.ToString() != "")
{
isBlank = false;
break;
}
}
if (isBlank)
{
form3.dbMetName.Rows.Remove(row);
}
}
Going down from the last row to the first is safer than going up, as you remove rows and shuffle ones you have checked!