473,387 Members | 1,304 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.

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 56157
When you bind your DataGridView to your datasource, use a bindingsource.

Dim nwData as CustomersDataSet = CustomersDataSet.GetCustomers()
m_CustomersGrid.DataSource = m_CustomersBindingSource
m_CustomersBindingSource.DataSource = nwData.Customers

Then you can sort using the BindingSource.

CustomersBindingSource.Sort = "ContactName ASC"

And you can find using the BindingSource.

Dim index as integer = _
CustomersBindingSource.Find("CompanyName", CompanyNameTextBox.Text)
If index <-1 then 'it was found; move to that position
CustomersBindingSource.Position = index
End If
Robin S.
-------------------------------------------
"Freddy Coal" <fr********@gmail.comwrote in message
news:OO*************@TK2MSFTNGP05.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.Columns(0), System.ComponentModel.ListSortDirection.Ascending)
'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 CustomersDataSet = CustomersDataSet.GetCustomers()
m_CustomersGrid.DataSource = m_CustomersBindingSource
m_CustomersBindingSource.DataSource = nwData.Customers

Then you can sort using the BindingSource.

CustomersBindingSource.Sort = "ContactName ASC"

And you can find using the BindingSource.

Dim index as integer = _
CustomersBindingSource.Find("CompanyName", CompanyNameTextBox.Text)
If index <-1 then 'it was found; move to that position
CustomersBindingSource.Position = index
End If
Robin S.
-------------------------------------------
"Freddy Coal" <fr********@gmail.comwrote in message
news:OO*************@TK2MSFTNGP05.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********@gmail.comwrote in message
news:uH**************@TK2MSFTNGP04.phx.gbl...
Hi Robin, Thanks for your answer, I solve the problem with this code:

DGV.Sort(DGV.Columns(0),
System.ComponentModel.ListSortDirection.Ascending) '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 CustomersDataSet = CustomersDataSet.GetCustomers()
m_CustomersGrid.DataSource = m_CustomersBindingSource
m_CustomersBindingSource.DataSource = nwData.Customers

Then you can sort using the BindingSource.

CustomersBindingSource.Sort = "ContactName ASC"

And you can find using the BindingSource.

Dim index as integer = _
CustomersBindingSource.Find("CompanyName", CompanyNameTextBox.Text)
If index <-1 then 'it was found; move to that position
CustomersBindingSource.Position = index
End If
Robin S.
-------------------------------------------
"Freddy Coal" <fr********@gmail.comwrote in message
news:OO*************@TK2MSFTNGP05.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
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...
0
by: inpuarg | last post by:
Is it possible to sort datagridview programmatically in virtualmode ? ..Sort() method isn 't working ?
4
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...
3
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...
2
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.", ...
2
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...
3
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,...
3
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...
0
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...
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
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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
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
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...

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.