Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get row index behind dataset relation

Status
Not open for further replies.

olichap

Programmer
Mar 20, 2001
389
US
Hi all,

I have an hierarchical dataset and a form with your standard parent/child grids (parent records displayed in grid at top of form, child grid below changes to show related details when parent changes).

I need to find a way to get the actual datatable row reference by the grid. For instance, the user might double-click on the 4th row in the child grid. In actuality this may refer back to row 12 in the datatable, not 4. How do I determine this number?

Thanks,

O.
 
I encountered this same problem recently. Unfortunately, I do not have an elegant solution, but I do have a solution. Loop through the rows of the underlying datatable and match the selected record on some unique criteria:

Code:
Dim r As Integer
Dim DTRow As Integer

For r = 0 To dt.Rows.Count - 1
    If dt.Rows(r).Item("AuthID") = dg.Item(SelectedRow, 0) Then
        If dt.Rows(r).Item("AppnID") = dg.Item(SelectedRow, 1) Then
            DTRow = r
            Exit For
        End If
    End If
Next

Note: dt is a datatable, dg is a datagrid.

This solution works ok for me because it is used in a data entry role, so there are never a huge amount of rows to loop through in the datatable. However, I believe that it would probably bog down if there were a large number of records. Hopefully seeing this hacked-together solution will prompt some guru to show me the error of my ways and provide a better solution (hint hint).

Anyway, hope this helps.

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top