[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)
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.
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.
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.