Sort a Datagridview with code.

  • Thread starter Thread starter Freddy Coal
  • Start date Start date
F

Freddy Coal

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
 
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.
 
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
 
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.
----------------------------------------
 
Back
Top