473,756 Members | 2,383 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1347
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.

CustomersBindin gSource.Sort = "ContactNam e 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 CustomersDataSe t = CustomersDataSe t.GetCustomers( )
CustomersGrid.D ataSource = CustomersBindin gSource
CustomersBindin gSource.DataSou rce = nwData.Customer s

Robin S.
-----------------------------
"vbt" <tb***@cwnet.co mwrote in message
news:uZ******** ******@TK2MSFTN GP06.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:

CustomersBindin gSource.Sort = "ContactNam e ASC"

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

Robin S.
------------------
"vbt" <tb***@cwnet.co mwrote in message
news:uR******** ******@TK2MSFTN GP06.phx.gbl...
Thanks,

By using your example:

CustomersBindin gSource.Sort = "ContactNam e 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
6414
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 gave it a try using the example given in
1
3209
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 datasources. Then at run time when I would bind a dataset to the grid it would display the tablestyle associated with the dataset. How do I do this in VS2005? 2) I do all my databinding to the datagridview at run time, but setup my columns as unbound...
10
7797
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: Properties.Settings.Default.DGV = myDataGridView; After I closed the program, the user.config file shows an empty value, so apparently that is not the way to do it.
7
12630
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 the background for my question... Before I switched my application over to the Fx 2.0, I used a DataGrid to display my data. I would store different DataGridTableStyles (each one with a custom set of columns) in the DataGrid.TableStyles property...
0
308
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 using the DataGridView.
0
988
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 happing? I have the DataGridView.EditMode set to “EditOnEnter”.
3
6330
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 to get the data in a datagridview to change. For example 2 columns are ID and amount_paid, the datagridview loads on form load with all ID's and amounts. How do I get it to only bring back the selected ID. Sounds like I may need to change the SQL...
6
4411
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 (Multiselect=false) from DGV - to do that I tried this: DGV.ClearSelection() Cosmetically this appears to work but it appears that the DGV still stores the index value of the selected row. If the 1st row I click on after executing ClearSelection() is the row...
1
2845
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 controls are locked on this form. I have another windows form call "ChildForm" that inherits "BaseForm". When I open"BaseForm: in VS2005 I can see both the DataGridView and the button and I can view all of the properties of these controls. ...
2
8453
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 click on appropriate row of the datagridview.Grid has only one event "cellcontentclick" is displayed.But i want to use "cellclick" or "selectionchanged" event of datagridview. So plz help me...How to do this....? Thax in advance.......
0
9456
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9275
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9872
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9843
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6534
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5142
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3805
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3358
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.