By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,087 Members | 1,508 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,087 IT Pros & Developers. It's quick & easy.

Listbox ?

P: n/a
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?
Nov 16 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
1) listBox.SelectedItem.Text
2) listBox.SelectedIndex
3) listBox.GetChildAtPoint(...) != null

"John S" <jo********@cinfin.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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?

Nov 16 '05 #2

P: n/a
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".
"John S" <jo********@cinfin.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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?


Regards

Marcin
Nov 16 '05 #3

P: n/a
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

--
B\rgds
Stoitcho Goutsev (100) [C# MVP]
"Violeta Dabnishka" <vd********@hotmail.com> wrote in message
news:OE**************@TK2MSFTNGP12.phx.gbl... 1) listBox.SelectedItem.Text
2) listBox.SelectedIndex
3) listBox.GetChildAtPoint(...) != null

"John S" <jo********@cinfin.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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?


Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.