Home All Groups Group Topic Archive Search About

DataGridView (VS2005)

Author
27 Nov 2006 11:40 PM
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.

Author
28 Nov 2006 12:13 AM
RobinS
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.
>
>
Author
28 Nov 2006 12:34 AM
vbt
Thanks,

By using your example:

CustomersBindingSource.Sort = "ContactName ASC"

I am back on track
Author
28 Nov 2006 6:36 AM
RobinS
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
>
>