By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,563 Members | 1,307 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,563 IT Pros & Developers. It's quick & easy.

Generate Columns Dynamically

P: n/a
I have a datagrid that will display data from the database. Each user will
specify list of columns he wants to see and in the order he wants to see.
User A can specify that he wants to see only columns A,B,C and in the order
A,B,C and the user might say I want to see only only columns A,G,H but the
order should be
G,A,H. It's possible that column G might have a hyperlink.

How can I do it in Dot.Net? Any help will be appreciated.

Tahnks,
Andy
Dec 22 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hi Andy,

To dynamically add columns to a grid, you create DataGridColumnStyle objects
and add them to the GridColumnStyles collection of an object called a
TableStyle.

1. Drop a grid on a form
2. Add a TableStyle to the grid. For sake of example, lets say you name it
oTableStyle
3. When you know the name of the datatable you are binding the grid to, you
set the MappingName of oTableStyle to the name of the datatable
4. When you are adding the columns, you create a DataGridTextBoxColumn or
DataGridBoolColumn, set the MappingName to the name of the field in the
DataTable.
5. Add the columnstyle object to oTableStyle.GridColumnStyles collection.

oTableStyle.MappingName="MyTable"

Dim oColumn As DataGridTextBoxColumn

oColumn = New DataGridTextBoxColumn()
oColumn.MappingName = "Age"

oTableStyle.GridColumnStyles.Add(oColumn)

oColumn = New DataGridTextBoxColumn()
oColumn.MappingName = "ZipCode"

oTableStyle.GridColumnStyles.Add(oColumn)

Dec 27 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.