hide Columns in Datagrid

rfazendeiro

Centurion
Joined
Mar 8, 2004
Messages
110
Hi to all,

I have a DataSet which i populate it with all the information that exists in a table in my database.

I will bind that DataSet to a DataGrid to show the information but i don't what to show all columns that exists in the DataSet.

So how can i limit what appears in the datagrid?? do i have to make a new DataSet with only the information i want?

thx to all
 
You have to use a DataGridTableStyle. Set the MappingName of the table style to the name of the DataTable you want displayed in the grid. Create DataGridTextBoxColumn's for each column you would like to display in the grid. Set the MappingName to the name you gave each column in your DataTable. Add each DataGridTextBoxColumn to the DataGridTableStyle. Add the DataGridTableStyle to the DataGrid's TableStyles collection. If any of this isn't clear let me know. I'll give you some example code.

Todd

Todd
 
thx for the replys...

but i found a good solution to deal with the problem. here is what i do:

MyDataSet.Tables[0].Columns["Col1"].ColumnMapping = MappingType.Hidden;
MyDataSet.Tables[0].Columns["Col2"].ColumnMapping = MappingType.Hidden;
....

and i do this for all the columns i want to hide....and it works :D
 
Back
Top