PEIAFowler
asked on
Need help with Datagrid Sorting
I am looking for some help in fixing a datagrid problem. I am using the following code to capture a double click and open our Order Entry form:
'Add Textbox Double Click Hander
AddHandler dgcsOrderID.TextBox.Double Click, New EventHandler(AddressOf TextBoxDoubleClickHandler)
'Opens Order Form with Double Clicked Order ID
Private Sub TextBoxDoubleClickHandler( ByVal sender As Object, ByVal e As EventArgs)
Dim drID As DataRow = objdsOrders.qryLIST_Orders .Rows(dgOr ders.Curre ntCell.Row Number)
Dim intOrderID As Integer = drID.Item("OrderID")
If intdblclickcount = 0 Then
OpenDisplay(intOrderID)
intdblclickcount = 1
End If
End Sub
This works fine when the form is first opened. However, when I sort on any column header, the data sorts, but apparently, the underlying data [objdsOrder.qryLIST_Orders .Rows(dgOr ders.Curre ntCell.Row Number)] does not. When I double click the order ID, it opens the original unsorted value of that row, not the display data. For example:
Before I sort the data:
Order Customer
00001 Bob
00002 Steve
00003 Alan
Clicking on row one opens Bob's order - this is fine.
After I sort the data:
Order Customer
00003 Alan
00001 Bob
00002 Steve
Clicking on row one still opens Bob's order - this is not fine.
I need a way to retrieve the sorted data, and points will be awarded to code that accomplishes that. TIA.
'Add Textbox Double Click Hander
AddHandler dgcsOrderID.TextBox.Double
'Opens Order Form with Double Clicked Order ID
Private Sub TextBoxDoubleClickHandler(
Dim drID As DataRow = objdsOrders.qryLIST_Orders
Dim intOrderID As Integer = drID.Item("OrderID")
If intdblclickcount = 0 Then
OpenDisplay(intOrderID)
intdblclickcount = 1
End If
End Sub
This works fine when the form is first opened. However, when I sort on any column header, the data sorts, but apparently, the underlying data [objdsOrder.qryLIST_Orders
Before I sort the data:
Order Customer
00001 Bob
00002 Steve
00003 Alan
Clicking on row one opens Bob's order - this is fine.
After I sort the data:
Order Customer
00003 Alan
00001 Bob
00002 Steve
Clicking on row one still opens Bob's order - this is not fine.
I need a way to retrieve the sorted data, and points will be awarded to code that accomplishes that. TIA.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Worked like a charm - thanks!
you need to pull the data from your datagrid
just cut your code down to
Dim drID As DataRow = dgOrders.CurrentCell.RowNu
Dim intOrderID As Integer = dgOrders.Item(dgOrders.Cur
just replace dgOrders.CurrentCell.RowNu
~b