0
It took me two iterations to do this work, one to go through the columns of the datagridview and store the name of the columns that have the row with null value and the second only to remove. This is because if I removed the column in the first iteration, the collection would be modified and the result would not be as desired.
//lista para ir armazenando o nome das colunas que irão ser removidas
List<string> columnNames = new List<string>();
//percorre as colunas do datagridview
foreach (DataGridViewColumn column in dataGridView1.Columns)
{
//verifica se o valor da primeira linha é igual a DBNull.Value
if (dataGridView1[column.Index, 0].Value == DBNull.Value)
{
//adiciona a coluna a lista para depois ser removida
columnNames.Add(column.Name);
}
}
//percorre a lista para ir removendo as colunas
foreach (string columnName in columnNames)
{
dataGridView1.Columns.Remove(dataGridView1.Columns[columnName]);
}
Very good! Thanks Marcos! Solved a problem I was days away! Congratulations!
– Alan Veloso