URGENT question about binding collection to a datagrid onitemdatabound

I

ITnerd

The following code works to hide specific columns before they are bound to a
datagrid that has "autogeneratecolumns=true"
enabled. My question is: is there any way to do the same from a bindable
user defined collection? I have a "message" class that I don't want to have
to
munge into a DataTable to get the desired effect.

public void Item_Bound(Object sender, DataGridItemEventArgs e)
{

DataTable dt = MyDataGrid.DataSource as DataTable;
DataColumnCollection dc = dt.Columns;
e.Item.Cells[dc.IndexOf(dc["MessageText"])].Visible = false;

}

Thanks in advance.
 
G

Giorgio Parmeggiani

Hi

I think that you can use this code, for any datasource, to hide your column:

public void Item_Bound(Object sender, DataGridItemEventArgs e)
{
foreach(TableCell cell in e.Item.Cells)
{
if(cell.Text == "MessageText") cell.Visible = false;
}
}

Giorgio
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top