DataGridView (VS2005)

  • Thread starter Thread starter vbt
  • Start date Start date
V

vbt

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.
 
Thanks,

By using your example:

CustomersBindingSource.Sort = "ContactName ASC"

I am back on track
 
Back
Top