Datagrid formatting

J

John

Hi

I am binding my datagrid like this;

MyDataGrid.SetDataBinding(ds, "MyTable") ' ds is the dataset

The problem is this bring all fields from the table. How can I restrict some
of the columns from appearing? Also how can I change the order and widths of
the grid columns?

Thanks

Regards
 
D

Dmitriy Lapshin [C# / .NET MVP]

Hi John,

This is achieved through usage of the DataGridTableStyle and
DataGridColumnStyle classes. You should create a DataGridTableStyle with
MappingName equal to "MyTable" and tune up table-wide properties like
background color if you need it. Then, add instances of
DataGridTextBoxColumn (or DataGridBoolColumn if you need such type of
column) for the data columns you want to display in order you want them to
display. MappingName property of each of the grid columns should correspond
to the name of the data column in the data table.

More information and examples on this can be found in MSDN Library.
 

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

Top