BrianMc1958
asked on
LAZY PERSON: Code to hide null columns in table?
Dear Experts,
I am a lazy person who could figure this out myself eventually, but...
Could anyone tell me how to hide all columns in a (datagrid) table in which all values are null?
Thanks!
--BrianMc1958
I am a lazy person who could figure this out myself eventually, but...
Could anyone tell me how to hide all columns in a (datagrid) table in which all values are null?
Thanks!
--BrianMc1958
ASKER
Sorry. I meant all null cells. I need to have the entire column hidden in that case, as I have a few tables with just a few rows but lots of empty columns. (All the values in the columns are empty.)
ASKER
I did this within Excel once, and had to loop through all the rows. That's practical here because there are few rows (but many, many columns...)
Is this Winforms or APS.NET?
ASKER
Winforms. Sorry to take so long. Back is out. Working (painfully) from home...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Dear anyoneis,
Again, sorry to ignore you for so long. Back has been very out. Thanks so much for the code. I'll give it a try!
--BrianMc1958
Again, sorry to ignore you for so long. Back has been very out. Thanks so much for the code. I'll give it a try!
--BrianMc1958
Brian, you probably saw this, but I left out an optimization in the inner loop that would be important if the number of rows gets larger:
for (int j = 0; j < ta.Rows.Count; j++)
{
if (ta.Rows[j][i] != System.DBNull.Value)
{
dataGridView1.Columns[i].V isible = true;
break;
}
}
It would also be interesting to compare performance against this, which works fine also:
for (int i = 0; i < ta.Columns.Count; i++)
{
string filter = ta.Columns[i].ColumnName + " IS NOT NULL";
if (ta.Select(filter).Length > 0)
{
dataGridView1.Columns[i].V isible = true;
}
}
Ciao!
David
for (int j = 0; j < ta.Rows.Count; j++)
{
if (ta.Rows[j][i] != System.DBNull.Value)
{
dataGridView1.Columns[i].V
break;
}
}
It would also be interesting to compare performance against this, which works fine also:
for (int i = 0; i < ta.Columns.Count; i++)
{
string filter = ta.Columns[i].ColumnName + " IS NOT NULL";
if (ta.Select(filter).Length > 0)
{
dataGridView1.Columns[i].V
}
}
Ciao!
David
You can use a tablestyle and then set the nulltext for that column to a blank string.