|
-
Feb 16th, 2007, 08:37 PM
#1
Thread Starter
Frenzied Member
[RESOLVED] [2005] Sorting a DataGridView before showing it
I am creating my own datatable to feed a DataGridView but the initial sorting(if there is one) is not the one that I need. I am re-sorting it afterwards but it takes some time. Is it possible to somehow provide an already sorted stuff prior to the visual fill?
This is how I am doing it now:
VB Code:
GridFiles.DataSource = workTable
GridFiles.Sort(GridFiles.Columns("Website"), System.ComponentModel.ListSortDirection.Ascending)
-
Feb 16th, 2007, 08:56 PM
#2
Re: [2005] Sorting a DataGridView before showing it
Bind the DataTable to a BindingSource, set the Sort property of the BindingSource, bind the BindingSource to the grid.
Better yet, use an ORDER BY clause in your SQL query to get the data in the order you need in the first place.
-
Feb 16th, 2007, 09:10 PM
#3
Thread Starter
Frenzied Member
Re: [2005] Sorting a DataGridView before showing it
Thanks, I tried workBinding.Sort = "Website ASC" and is a bit faster now.
There is no SQL source, I am building the table with
VB Code:
workTable.Columns.Add("Website", Type.GetType("System.String"))
etc...
My table is just not coming out sorted the way I'd like it to be.
-
Feb 16th, 2007, 09:14 PM
#4
Re: [2005] Sorting a DataGridView before showing it
If you're adding each row manually then it will be in the order that you add the rows. If you want the rows in a different order then you can add them in a different order. Having said that, sorting via the BindingSource is just as easy.
Also, if you didn't want to use a BindingSource for some reason you could have just set the DefaultView.Sort property of the DataTable. I'd stick with the BindingSource though.
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
|