Hierarchical ListBox LastIndex does not update after a Collapse event

  1. 3 months ago

    Tim J

    Jun 11 Pre-Release Testers, Xojo Pro Dehydrating in AZ
    Edited 3 months ago

    I just discovered the cause of an odd bug on many of my apps that I'm building under 18r1.1. If you expand a folder, add the children for that expansion, and then collapse the row, the listbox's LastIndex does not decrement to the collapsed row count.

    For example:

    Hierarchical ListBox with 3 Folders
    LastIndex = 2
    Expand one of the Folders and add 10 child rows
    LastIndex = 12
    Collapse the Folder
    LastIndex = 12

    Nothing that I do can get the LastIndex back to 2.

    Mac OS 10.12.6, 10.13.5, and Windows 10 at this point.

    Anyone else?

    there is nothing documented that indicates that it should...

    LastIndex is the index of the last row added with AddRow/AddFolder or InsertRow
    The value of this would be meaningless should any other operation occur after one of these.

  2. Dave S

    Jun 11 Answer San Diego, California USA

    there is nothing documented that indicates that it should...

    LastIndex is the index of the last row added with AddRow/AddFolder or InsertRow
    The value of this would be meaningless should any other operation occur after one of these.

  3. Tim J

    Jun 11 Pre-Release Testers, Xojo Pro Dehydrating in AZ

    @Dave S there is nothing documented that indicates that it should...

    LastIndex is the index of the last row added with AddRow/AddFolder or InsertRow
    The value of this would be meaningless should any other operation occur after one of these.

    Good point and that answer points out my deeper mistake. As soon as I read it, I realized that I should have been using "ListCount" not "LastIndex" and the only thing that I can think of is that I let autocomplete fool me with the wrong item :D.

    Thanks, Dave.

  4. Emile S

    Jun 12 Europe (France, Strasbourg)

    Isn’t it ListIndex that you have to use ?

  5. Tim J

    Jun 12 Pre-Release Testers, Xojo Pro Dehydrating in AZ

    @Emile S Isn’t it ListIndex that you have to use ?

    In this case, I'm trapping mouse clicks in the dead area of the listbox, so I need to know the listcount.

  6. Emile S

    Jun 12 Europe (France, Strasbourg)

    @Tim J dead area of the listbox

    Care to explain what ypu mean by that ? A click after the last populated Row ?

  7. Dave S

    Jun 12 San Diego, California USA

    Listcount is how many rows are in the listbox
    ListIndex is the currently selected row.... so you may actually want Listindex = -1

  8. Douglas H

    Jun 12 Pre-Release Testers
    Edited 3 months ago

    I'm not sure that ListIndex - 1 is useful for too much. But ListCount - 1 may be what the OP was expecting LastIndex to represent.

    Edit: Just reread it and saw you said ListIndex = -1, where I first read it as ListIndex - 1.

  9. Tim J

    Jun 12 Pre-Release Testers, Xojo Pro Dehydrating in AZ
    Edited 3 months ago

    @Douglas H I'm not sure that ListIndex - 1 is useful for too much. But ListCount - 1 may be what the OP was expecting LastIndex to represent.

    Edit: Just reread it and saw you said ListIndex = -1, where I first read it as ListIndex - 1.

    Nope - I'm manually managing mouse clicks to gain consistency across all three platforms. You can have a ListBox that is 20 rows high, but only contains 8 rows/folders. I need to know WHERE the user clicked and the starting point is - was it in a populated row, or was it in the empty space? ListCount -1 is what I need.

    @Emile Schwarz Care to explain what ypu mean by that ? A click after the last populated Row ?

    Exactly that, and "ListIndex = -1" doesn't get the specific info that I'm looking for.

  10. Emile S

    Jun 12 Europe (France, Strasbourg)
    Edited 3 months ago

    @Tim J "ListIndex = -1" doesn't get the specific info that I'm looking for.

    Why ?

    IMHO: this is exactly what you need. A click in a Listbox but not in the Heading or in a valid Row (an existing Row) returns -1. So

    If Me.ListIndex = -1 Then
    // Click outside of a Row
    End If

    Just check.

    Edit: Read ListBox.ListIndex .

  11. Emile S

    Jun 12 Europe (France, Strasbourg)

    Breakfast was good (to think).

    If your code in Click Event looks like:

    If Y > (Listbox1.ListCount * Listbox1.RowHeight) Then
      TextArea1.Text = ""
      TextField1.Text = ""
    End If

    You can either use:

    If Listbox1.ListIndex = -1 Then
      TextArea1.Text = ""
      TextField1.Text = ""
    End If

    Is-it clear now ?

or Sign Up to reply!