[Win32API] List Box - finding index by "Data Value"

there's a message LB_SETITEMDATA that will set a special value for a specified list box item, for example let's say I have 3 list box items:

First Item
Second Item
Third Item

and every item has it's special value, ofcourse, they are mixed, in this order:

2
3
1

so the First Item has value of 2 etc, now, HOW do I get an index of an item with value 3? (Second Item) without knowing it's name?

something like message (fictional)

LB_GETINDEXBYITEMDATA, so the code would look like this:

int index = SendMessage(GetDlgItem(hWnd, IDC_CLIENTS), LB_GETINDEXBYITEMDATA, NULL, (LPARAM)3);

this would set index to "1", since the item that has ITEMDATA set to 3 is "Second Item", which is at position 1 (starting from 0 with first)
Last edited on
anyone?
If the numbers are sequentials and are not too bug, you could use a look up table, ie an array that you initialize such that array[value] == index.

Or you could use a std::map.
that makes no sense, how would I find it then? when I remove one, the index of those below will change
Topic archived. No new replies allowed.