|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
DataGridView (VS2005)I am using a DataGridView control. Using code, I would like to select a
column by column number and have it sort the Data based on the select column. All examples I have found, presume that a column has been selected by the user first but this may not be the case. Any help would be greatly appreciated. Are you using VS2005? Are you using databinding?
If you're using a Binding Source to bind the data to a database, you can sort using the binding source, and it will automatically change the order of the grid. CustomersBindingSource.Sort = "ContactName ASC" If you using data binding, but aren't using a binding source, you can easily add it: Add a binding source to your form (drag it on to the form from the toolbox). Set the name over in the properties. In your code where you load the grid, set the data source for the grid to the binding source. Set the data source for the binding source to the dataset. Here's an example with NorthWind: Dim nwData as CustomersDataSet = CustomersDataSet.GetCustomers() CustomersGrid.DataSource = CustomersBindingSource CustomersBindingSource.DataSource = nwData.Customers Robin S. ----------------------------- Show quoteHide quote "vbt" <tb***@cwnet.com> wrote in message news:uZV8o1nEHHA.4832@TK2MSFTNGP06.phx.gbl... >I am using a DataGridView control. Using code, I would like to select a >column by column number and have it sort the Data based on the select >column. > > > > All examples I have found, presume that a column has been selected by the > user first but this may not be the case. > > > > Any help would be greatly appreciated. > > Thanks,
By using your example: CustomersBindingSource.Sort = "ContactName ASC" I am back on track Cool. Glad I could help.
Robin S. ------------------ Show quoteHide quote "vbt" <tb***@cwnet.com> wrote in message news:uRTluToEHHA.3768@TK2MSFTNGP06.phx.gbl... > Thanks, > > By using your example: > > CustomersBindingSource.Sort = "ContactName ASC" > > I am back on track > >
word automation vb.net
Arranging window screens on multi-monitor Desktop Re: Help needed in using FSO's, TextStreams, etc. --- Code Review and Advice requested listbox's SelectedIndexChanged keep fire Array Question, Out of Bounds better way to program than this? set refresh rate for an active browser window File and Database Search Display Outlook Recipient Window from vb.net Re: Is VB.NET Stable?? |
|||||||||||||||||||||||