How to hide a row in a ListBox

I have a ListBox that is supposed to show only certain rows based on some radio buttons. I was wondering if there was a way to hide a row in a ListBox, without deleting it? The only way I can get it to do this is by calling


in the paintRowBackground function this works good, except that it leaves blank spots where the rows are hidden, without shifting the visible rows to the top. Any help would be greatly appreciated.

You could have an array of pointers to the visible itemdata objects.

e.g. If your system is currently

getNumRows () { return items.size(); }

you could change it to

getNumRows () { return visibleItems.size(); }

When the radiobuttons change, you can refresh the contents of the ‘visibleItems’ array and call updateContent() in the list.

If I change the getNumRows() function it doesn’t work, because it just shows that number of rows that occur at the top of the table and that was my original problem the visible aren’t getting pushed to the top. Is there a way to refresh the ListBox with just the visible contents?

What a messy approach to the problem! Why not just do it properly and make your list show the rows that should be showing, based on whatever it is that the user has selected?

You’ve missed out on the concept graystatic - you take the list item data (in the item painting bit) from the pointers in the visibleItems array instead of your main items array. When the radiobuttons change, you alter the contents of visibleItems to list the items that are visible. You could do that by some complex addition/removal, or just a basic updateVisibleItems() function that clears and rebuilds the visibleItems array based on radio buttons

This means the list only shows items that are visible.

I tried doing something like that, but I couldn’t get it to work right. I am using XmlElements to hold my data. So I had one that contains all of my data and another that when the radiobutton changes it gets cleared and then gets items added to it, from the one containing all items, based on the radiobuttons using the forEachXmlChildElement () and addChildElement (), but it doesn’t work. Most of the time when I try doing this it crashes.

you shouldn’t be using an XmlElement and children for the visible items array. you just want to hold pointers to them - if you put them into an xmlelement, when you clear it they’ll be deleted [because the element takes ownership of its children]. This will obviously cause you problems as your main data element will be full of danglies.

consider this (in sparse-o-pseudo-vague-o-code)

ListBox* list;
XmlElement data; // contains child elements - 'ALL' rows
Array<XmlElement*> visibleElements; // holds pointers to visible elements

When the buttons change:
forEachXmlChildElement (data, child)
   if (visibleAccordingToButtons(child)) visibleElements.add (child);
list->updateContent ();

and of course...

int getNumRows()
   return visibleElements.size();

and then of course, in the paint item function, you want to use...

XmlElement* item = visibleItems.getUnchecked(rowNumber);
(and then paint using the element retrieved)

Thanks, that looks like it will do exaclty what I want, I’ll have to try it out, later today.