ListBox - How do I tell which item I've selected from the list box?

How do I tell which item I've selected in the list box? I don't want to retrieve the string from the selected field, but rather just identify which field I've selected in the list box. For example, once I am able to find out which field I've selected, I can use it to do something like this:

1
2
3
4
5
6
7
8
if (ListBoxSelectedField == 1)
{
    Do this;
}
else if (ListBoxSelectedField == 2)
{
    Do this;
}


A visual representation of what I mean by "field":
http://i48.tinypic.com/14312x.jpg

Basically the highlighted/selected field would be called field #5, but how would I go about identifying IF that field is field #4, #5, or #6?

Thanks in advance.
What you call "field" is really an item. Fields are usually represented by columns.

To get the selected item in a listbox that allows only one selection, use SendMessage() to issue a LB_GETCURSEL message. The return value is the index number you are looking for. Read more about it @ http://msdn.microsoft.com/en-us/library/windows/desktop/bb775197(v=vs.85).aspx .
Thanks! I'll try to play around with that first and see what I get.
Topic archived. No new replies allowed.