I did this to show selected item in listbox !!
MsgBox(ListBox1.SelectedItem)
it throws an error ???
Printable View
I did this to show selected item in listbox !!
MsgBox(ListBox1.SelectedItem)
it throws an error ???
B/c the selecteditem property returns an object type. You need to use the tostring() property.
Code:private void button1_Click(object sender, System.EventArgs e) {
MessageBox.Show(this.listBox1.SelectedItem.ToString());
}
this won't work .
Sorted out :D . It's matter of code ordering
What do you mean 'wont work'?
ToString isn't a member of SelectedItem .In other words, When I press (.) I only get this method (GetType) no ToString method !Quote:
Originally posted by Lethal
What do you mean 'wont work'?
All objects are ultimately derived from System.Object. This super class exposes a virtual method 'ToString'. The selecteditem property returns an object, therfore you can use the tostring method.
Code:Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MessageBox.Show(Me.ListBox1.SelectedItem.ToString())
End Sub
That's right Lethal , I do agree with you but what confused me was : ToString isn't existed under SelectedItem Property.Thanx anyways for this note :) .
Yeah, i noticed that. I wonder why the guys down in redmond decided to hide (in the sense of visibility through the ide) some of the base members from extended classes. :rolleyes:
Maybe this is a part of MS decision to hide some memebers from intellisense. Go to
Tools->Options: Text Editor->Basic->General: Uncheck Hide advanced members
Then you will see more entries.
Thank you Iouri . That did the trick :D