473,387 Members | 1,545 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

DataGridView (VS2005)

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.
Nov 27 '06 #1
3 1321
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.
-----------------------------
"vbt" <tb***@cwnet.comwrote in message
news:uZ**************@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.


Nov 27 '06 #2
vbt
Thanks,

By using your example:

CustomersBindingSource.Sort = "ContactName ASC"

I am back on track
Nov 28 '06 #3
Cool. Glad I could help.

Robin S.
------------------
"vbt" <tb***@cwnet.comwrote in message
news:uR**************@TK2MSFTNGP06.phx.gbl...
Thanks,

By using your example:

CustomersBindingSource.Sort = "ContactName ASC"

I am back on track


Nov 28 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: dbuchanan | last post by:
Hello, Is this a bug? Is there some kind of work around? I want to add default values for a few columns in my datagridview I found the "DefaultValuesNeeded" event for the datagridview I...
1
by: Brian | last post by:
I've got a couple questions on the new Datagridview control in VS2005. 1) In the old datagrid control at design time I was able to add multiple tablestyles with columns from different...
10
by: michael sorens | last post by:
Is it possible to store an unbound DataGridView component into a setting? I naively tried defining a Setting that is a DataGridView called DGV, then simply assigning it:...
7
by: Mitchell S. Honnert | last post by:
Is there an equivalent of the DataGrid's DataGridTableStyle for the DataGridView? If not, is there an easy way to duplicate the DataGridTableStyle's functionality for the DataGridView? Here's...
0
by: vbt | last post by:
(VS2005) I am new to using the DataGridView and I have read most everything I can find on this subject. But obviously I am not see the hole picture. I am trying to update a data base...
0
by: tom | last post by:
I am working in VS2005 with the DataGridView. When I click on a cell and move on by clicking on another cell all the data is removed from the first cell. Is there a way to prevent this from...
3
by: =?Utf-8?B?Sm9obiBCdW5keQ==?= | last post by:
New to databinding in vs2005, I always did it manually in 2003. I have no problem loading comboboxes, and a change in that combobox changes the data in the textboxes but I can not figure out a way...
6
by: hzgt9b | last post by:
Using VS2005, VB.NET, I have a windows app with a DataGridView (lets call it DGV). At some point in the life of my app I want to clear the selection of the currently selected row...
1
by: mtembene | last post by:
I have a windows form "BaseForm" that contains a DataGridView that is not bound to any datasources and a button. Both of these controls have a modifier of "Protected Internal" and none of the...
2
by: hnpatel | last post by:
Hi to All, How to use mouse click event for datagridview in c# in vs2005? I m using datagridview in c# application.I had bound data in datagridview.I want to display data in textbox when i...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.