kdunnett
asked on
Hide datagrid columns when there is no data in the column
Good night all,
I have a datagrid that gets binded by some dyamic query. There will be times when there are full columns in the datagrid that won't have any data. Is there a way I can loop through a datagrid, say pick a column and check all rows to see if there is any data, if not, make the column visable = false and then go to next column?
Thanks,
Kris
I have a datagrid that gets binded by some dyamic query. There will be times when there are full columns in the datagrid that won't have any data. Is there a way I can loop through a datagrid, say pick a column and check all rows to see if there is any data, if not, make the column visable = false and then go to next column?
Thanks,
Kris
ASKER
How do you loop through a datagrid in 1.1? its not like a datatable where u can use a datarow...
ideas?
ideas?
What is the DataGrid bound to?
Bob
Bob
ASKER
A dataset, which is a sql statement.
i'm thinking of doing something like the below... just call it for every column that is in the dataset, and handle bringing back the columns via sql:
private void CreateBoundColumn(string columnName, string columnTitle, bool visable)
{
BoundColumn bc = new BoundColumn();
bc.DataField = columnName;
bc.HeaderText = columnTitle;
if(!visable)
bc.Visible = false;
this.dg.Columns.Add(bc);
}
i'm thinking of doing something like the below... just call it for every column that is in the dataset, and handle bringing back the columns via sql:
private void CreateBoundColumn(string columnName, string columnTitle, bool visable)
{
BoundColumn bc = new BoundColumn();
bc.DataField = columnName;
bc.HeaderText = columnTitle;
if(!visable)
bc.Visible = false;
this.dg.Columns.Add(bc);
}
If you have a DataSet, then loop through the DataTable, and check the values in a particular column to see if they are all blank.
Bob
Bob
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks... that's its.
I knew what it was... just up for too long and getting forgetfull.
I knew what it was... just up for too long and getting forgetfull.
Bob