473,699 Members | 2,768 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Sort a Datagridview with code.

Hi, I'm learning to use the Datagridview; I would like sort a column of my
DGV, but with code, not with user click over the column, how make that?; Mi
other question is how
search for a especific chain in my DGV?.

Thanks in advance for any help, I'm using VB.Net in VS2005.

Freddy Coal
Feb 26 '07 #1
3 56188
When you bind your DataGridView to your datasource, use a bindingsource.

Dim nwData as CustomersDataSe t = CustomersDataSe t.GetCustomers( )
m_CustomersGrid .DataSource = m_CustomersBind ingSource
m_CustomersBind ingSource.DataS ource = nwData.Customer s

Then you can sort using the BindingSource.

CustomersBindin gSource.Sort = "ContactNam e ASC"

And you can find using the BindingSource.

Dim index as integer = _
CustomersBindin gSource.Find("C ompanyName", CompanyNameText Box.Text)
If index <-1 then 'it was found; move to that position
CustomersBindin gSource.Positio n = index
End If
Robin S.
-------------------------------------------
"Freddy Coal" <fr********@gma il.comwrote in message
news:OO******** *****@TK2MSFTNG P05.phx.gbl...
Hi, I'm learning to use the Datagridview; I would like sort a column of
my
DGV, but with code, not with user click over the column, how make that?;
Mi other question is how
search for a especific chain in my DGV?.

Thanks in advance for any help, I'm using VB.Net in VS2005.

Freddy Coal

Feb 27 '07 #2
Hi Robin, Thanks for your answer, I solve the problem with this code:

DGV.Sort(DGV.Co lumns(0), System.Componen tModel.ListSort Direction.Ascen ding)
'Where DGV is a DataGridView

Excuse me, but I don´t understand your second answer; I would like search a
chain (form example "Claymore Street") inside of my DGV; I make that
searching cell by cell with row and columns cycles, but I would like know if
Vb.Net have any instruction for make this search.

Thanks a lot again, your help is very appreciated.

Freddy Coal

"RobinS" <Ro****@NoSpam. yah.nonewrote in message
news:Dq******** *************** *******@comcast .com...
When you bind your DataGridView to your datasource, use a bindingsource.

Dim nwData as CustomersDataSe t = CustomersDataSe t.GetCustomers( )
m_CustomersGrid .DataSource = m_CustomersBind ingSource
m_CustomersBind ingSource.DataS ource = nwData.Customer s

Then you can sort using the BindingSource.

CustomersBindin gSource.Sort = "ContactNam e ASC"

And you can find using the BindingSource.

Dim index as integer = _
CustomersBindin gSource.Find("C ompanyName", CompanyNameText Box.Text)
If index <-1 then 'it was found; move to that position
CustomersBindin gSource.Positio n = index
End If
Robin S.
-------------------------------------------
"Freddy Coal" <fr********@gma il.comwrote in message
news:OO******** *****@TK2MSFTNG P05.phx.gbl...
>Hi, I'm learning to use the Datagridview; I would like sort a column of
my
DGV, but with code, not with user click over the column, how make that?;
Mi other question is how
search for a especific chain in my DGV?.

Thanks in advance for any help, I'm using VB.Net in VS2005.

Freddy Coal

Feb 27 '07 #3
I already answered that question in my previous post. If you want to know
how to do it without using a BindingSource, maybe someone else will answer
you.

Robin S.
----------------------------------------
"Freddy Coal" <fr********@gma il.comwrote in message
news:uH******** ******@TK2MSFTN GP04.phx.gbl...
Hi Robin, Thanks for your answer, I solve the problem with this code:

DGV.Sort(DGV.Co lumns(0),
System.Componen tModel.ListSort Direction.Ascen ding) 'Where DGV is a
DataGridView

Excuse me, but I don´t understand your second answer; I would like search
a chain (form example "Claymore Street") inside of my DGV; I make that
searching cell by cell with row and columns cycles, but I would like know
if Vb.Net have any instruction for make this search.

Thanks a lot again, your help is very appreciated.

Freddy Coal

"RobinS" <Ro****@NoSpam. yah.nonewrote in message
news:Dq******** *************** *******@comcast .com...
>When you bind your DataGridView to your datasource, use a bindingsource.

Dim nwData as CustomersDataSe t = CustomersDataSe t.GetCustomers( )
m_CustomersGri d.DataSource = m_CustomersBind ingSource
m_CustomersBin dingSource.Data Source = nwData.Customer s

Then you can sort using the BindingSource.

CustomersBindi ngSource.Sort = "ContactNam e ASC"

And you can find using the BindingSource.

Dim index as integer = _
CustomersBindin gSource.Find("C ompanyName", CompanyNameText Box.Text)
If index <-1 then 'it was found; move to that position
CustomersBindin gSource.Positio n = index
End If
Robin S.
-------------------------------------------
"Freddy Coal" <fr********@gma il.comwrote in message
news:OO******* ******@TK2MSFTN GP05.phx.gbl...
>>Hi, I'm learning to use the Datagridview; I would like sort a column of
my
DGV, but with code, not with user click over the column, how make
that?; Mi other question is how
search for a especific chain in my DGV?.

Thanks in advance for any help, I'm using VB.Net in VS2005.

Freddy Coal


Feb 27 '07 #4

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

Similar topics

0
1155
by: William LaMartin | last post by:
I have just moved from Visual Studio 2003 to 2005 and am having a bit of trouble with saving changes in a dataviewgrid to the underlying Access database table. I thought I had all of this worked out with datagrids and datasets in 2003, but the same sort of code doesn't work when moved to 2005. So I looked at a Microsoft example for help. Specifically, in the example at...
0
4765
by: inpuarg | last post by:
Is it possible to sort datagridview programmatically in virtualmode ? ..Sort() method isn 't working ?
4
8631
by: Matt | last post by:
I have been searching all over the web for a way to sort a DataGridView based on the actual text being shown in a ComboBox column as opposed to the underlying value (an ID in this case). Can anyone tell me if this is even possible, and if so, how to do it? If this is completely impossible, how would you suggest going about sorting a ComboBox wherein the text displayed in the column is the client's name, and the underlying value is an ID? ...
3
11938
by: joey.powell | last post by:
I have a datagridview where I set its "DataSource" property to a DataSet and its "DataMember" property to a table within the DataSet. I need for the DataGridView to "sort" through the contents of the DataSet as it binds. Can I specify a column on the DataSet that, sorted, will control the order of the rows in the datagridview? It seems to just parse over the data in the DataSet and bind to it, without my being able to control the order...
2
29658
by: tee | last post by:
Hi, How do i sort datagridview programmically, current i have the following code but i keep get the error saying "DataGridView control must be bound to an IBindingList object to be sorted.", What is IBindingList and how would i go about using it. Here are my code private void dataGridView1_ColumnHeaderMouseClick(object sender,
2
9492
by: Claes Wedin | last post by:
Hi, We have a DataGridView and the user wants to be able to change the order on the rows by drag and drop. The best would be if a thick line showed where the row will be placed when moving over the grid (like it looks when moving things in the start-menu...). All examples I've found is with listviews and not datagridviews... Anybody done this or found an example..
3
4208
by: Frederik | last post by:
Hi group, I have a DataGridView that is mainly consisting of data bound columns. One column however is unbound. I'm not able to sort the grid on this column! Is that normal behaviour? If so, what are my options? Thanks (again) for your time, Frederik
3
1338
by: frenzy99 | last post by:
Can some one help me with this problem. I want to sort DataGridView based on the order in which values were added, not on the basis of any particular column, unlike the functionality provided by DataGridView.Sort()
0
5648
by: priyamtheone | last post by:
I'm trying to make a datagridview column to act like a datetimepicker column (C#.Net 2005). These are the behaviours that the dgv should have: 1) Initially all the cells of the dtp column should be blank unless they are filled by the user. 2) As soon as the user enters a cell, the dtp control should appear as the editing control of that cell. If there's a value in the cell beforehand, that value is set as the value of the dtp editing control...
0
9173
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8911
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
8882
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7748
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5872
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
4375
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...
1
3057
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
2345
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2009
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.