Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / General / December 2005

Tip: Looking for answers? Try searching our database.

Generate Columns Dynamically

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
andy - 22 Dec 2005 02:57 GMT
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
RickHodder - 27 Dec 2005 04:25 GMT
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)

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.