Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1105
UltraGrid Row Index
posted

I'm restrained by some abnormal conditions while in need of knowing what a row's index is.  Here's an example scenario:

1. Bind a datatable to the grid that contains 10 rows.  At this point I can programmatically get the 4th visible row in the grid by: Rows.GetRowAtVisibleIndex(3) or GetRowWithListIndex(3) or even Rows[3].

2. Sort the rows by some arbitrary column.  Now I want to programmatically get the 4th visible row.  I can no longer use Rows.GetRowWithListIndex(3) because the rows are sorted.  However Rows.GetRowAtVisibleIndex(3) still works.

3. Programmatically the user is able at run time to hide any number of columns.  The user happens to hide visible row 2.

4. Now I want to get the 4th visible row in the grid.  I still can't use Rows.GetRowWithListIndex(3) for the same reason as before.  But now I also can't use Rows.GetRowAtVisibleIndex(3) because GetRowAtVisibleIndex ignores rows with .hidden == true so GetRowAtVisibleIndex(3) would actually return the 5th physical row in the grid.

I'm aware that the entire point of ListIndex is to be able to link the bound data row to what is displayed.  But in my particular usage, my code is "dumb" to the bound data once it has occurred.  What I really need is a way to get a row at a visible position...even if that row happens to be hidden.  Is there no master list the grid keeps of rows that while still representing the logical order of the rows, doesn't exclude them for being hidden?

Thanks in advance for any help you can give me

Parents
  • 469350
    Verified Answer
    Offline posted

    Hi Chris,

    The grid keeps an unsorted master list internally, but it's not exposed publicly. In theory, you could access it using reflection, but I would strongly advise against that - not just for security reasons, but because you could easily access the list when it's not in a valid state and cause it to update itself at the wrong time. It would be very dangerous. But... if you want to try it, what you would do is use the internal UnSortedActualRows property on the Rows collection.

    I'm reading and re-reading your post, but I'm having a very hard time understand exactly what you want. You say you can't use GetRowWithListIndex because the grid rows are sorted. So you DO want to account for the sort order of the rows in the grid, but you DO NOT want to ignore rows that are hidden in the grid?

    If that's the case, then it sounds like you should just use grid.Rows[4]. Am I missing something?

Reply Children
No Data