Listbox ?

  • Thread starter Thread starter John S
  • Start date Start date
J

John S

How can you
1.) Get the text of an item selected?
2.) Get the index number of the item selected?
3.) Tell if the user clicked in a blank area?
 
1) listBox.SelectedItem.Text
2) listBox.SelectedIndex
3) listBox.GetChildAtPoint(...) != null
 
Hi,

<snip>

Little errata:

1) listBox.GetItemText(listBox.SelectedItem)

But i don't know how it works if nothing is selected.
2) listBox.SelectedIndex
3) listBox.GetChildAtPoint(...) != null

I'm not sure if this method works as John wants.
ListView has "GetItemAt(...)" that can return that info,
but i think that ListBox hasn't any method able to
do it "directly".

Regards

Marcin
 
Hi Violeta,
1) listBox.SelectedItem.Text

SelectedItem has no Text property brcause it is of type Object. As long as
the Listbox uses ToString method to get the text
listBox.SelectedItem.ToString() would be the correct way.
2) listBox.SelectedIndex

For 1) and 2 is multiselect is enabled SlectedItems and SelectedIndices
should be used
3) listBox.GetChildAtPoint(...) != null
It won't do as long the list box noramlly doesn't have child controls.
the correct would be

listBox.IndexFormPoint(...) != ListBox.NoMatches
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top