Link to home
Start Free TrialLog in
Avatar of PEIAFowler
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.DoubleClick, 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(dgOrders.CurrentCell.RowNumber)
        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(dgOrders.CurrentCell.RowNumber)] 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.

Avatar of bramsquad
bramsquad
Flag of United States of America image

its becuase your still pulling the data from your datasource

you need to pull the data from your datagrid

just cut your code down to

Dim drID As DataRow = dgOrders.CurrentCell.RowNumber
Dim intOrderID As Integer = dgOrders.Item(dgOrders.CurrentCell.RowNumber, dgOrders.CurrentCell.ColumnNumber)

just replace dgOrders.CurrentCell.RowNumber with a constant value where that field exists.

~b
ASKER CERTIFIED SOLUTION
Avatar of bramsquad
bramsquad
Flag of United States of America 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
Avatar of PEIAFowler
PEIAFowler

ASKER

Worked like a charm - thanks!