Link to home
Start Free TrialLog in
Avatar of MBHEY131
MBHEY131

asked on

Datagredview row selection sortmode

My datagridview is: "DATAGRIDVIEW1" which has several Columns, but the columns in question are "LastName" and "VIN"

And I have several chunks of code that Gets me to letting customers enter FIND DATA and the code does take them to the correct row within the "DATAGRIDVIEW1"  but after that I would like to REORDER MY "ROWS ONLY" TO REFLECT THE DATA THEY HAVE INPUT???

e.g.

If they select "LASTNAME" and  enter "SMITH"  I would like to reorder and show all the "SMITH'S" UNDER the row that they have selected.

Could anyone help me with the code
Avatar of MBHEY131
MBHEY131

ASKER

vb.net and vs2012
Avatar of Nasir Razzaq
It will have to be a custom sort

Example here

https://msdn.microsoft.com/en-us/library/ms171608%28VS.80%29.aspx
ok - I've got the sort problem fixed - here is my next trouble - once I have gotten to the correct row and sorted correctly the Selected Row is not visible on the screen unless you use the sidebar and go and find it - not a huge issue but I would like the system to bring the selected row to the visible screen??? Could you help with that code??
OK moving along now - the code "cform.CustomersBindingSource.MoveNext()" solved the datagridview1 to move to the selected row on the screen correctly, however somehow now we are getting an extra row selected for some reason:
Here's the code:
       cform.DataGridView1.AllowUserToAddRows = False
        For Each row As DataGridViewRow In cform.DataGridView1.Rows
            cform.CustomersBindingSource.MoveNext()
            If cform.DataGridView1.Rows(intcount).Cells(CellToLookIn).Value.ToString = CustText Then
                cform.DataGridView1.Rows(intcount).Selected = True
                FindCust = True
                Exit Function
            End If
            intcount = intcount + 1
        Next
        cform.DataGridView1.AllowUserToAddRows = True
 

Open in new window


the only thing I added was the "cform.CustomersBindingSource.MoveNext()" line ??
could you give me an example and tell me where to insert the example in the code?
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial