|
-
Mar 27th, 2007, 01:28 AM
#1
Thread Starter
Frenzied Member
[RESOLVED] [2005] Order columns in a datagridview
Hello,
Is there a way to manually order the columns in a grid.
My grid is bound to the datasource at run-time. So I can't change the order in the designer.
Is there a method to do that in code?
Many thanks,
Steve
-
Mar 27th, 2007, 01:36 AM
#2
Re: [2005] Order columns in a datagridview
You can change the order in the designer if you want to, assuming that you know what columns there will. Add the columns you want at design time, put them in the order you want and set their DataPropertyName properties so they know what data source columns to bind to at run time.
Alternatively, once the grid has auto-generated the columns you should be able to use the Remove and Insert methods of the grid's Columns collection, just like you can any other collection, to re-order the items it contains.
-
Mar 27th, 2007, 01:43 AM
#3
Thread Starter
Frenzied Member
Re: [2005] Order columns in a datagridview
Private Sub AdjustColumnOrder()
With customersDataGridView
.Columns("CustomerID").Visible = False
.Columns("ContactName").DisplayIndex = 0
.Columns("ContactTitle").DisplayIndex = 1
.Columns("City").DisplayIndex = 2
.Columns("Country").DisplayIndex = 3
.Columns("CompanyName").DisplayIndex = 4
End With
End Sub
-
Mar 27th, 2007, 03:22 AM
#4
Re: [2005] Order columns in a datagridview
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|