User Data on Lists / Multi Lists


18-08-2008 16:18:59

I've programmed a long time with the Microsoft Foundation Classes (MFC), so I'm a bit spoiled with some features ;-)

On I really miss in MyGui is the ability to store an arbitrary value (4 / 8 bytes, pointer size) with each Item in a List / MultiList. This would make it easy to directly link some data with items in the Lists, so it would be easy to:

(Pseudo-Code, beware...)

int indexOfNewItem = list.addItem("Hello World");
list.setItemData( indexOfNewItem, reinterpret_cast<long>(&myHelloData));

//later in callback..

HelloData* myHello = reinterpret_cast<HelloData*>(list.getItemData( indexOfSelectedItem ));

So there is no more user-side index-to-item data mapping :-)

I think this feature is really easy to implement, as you just have to store the additional value with each item and provide some accessor methods. The AddItem method returning the index of the new item would be good, too.