|
-
Mar 8th, 2003, 06:11 PM
#1
Thread Starter
Sleep mode
selected item in listbox ??[Resolved]
I did this to show selected item in listbox !!
MsgBox(ListBox1.SelectedItem)
it throws an error ???
Last edited by Pirate; Mar 9th, 2003 at 08:31 AM.
-
Mar 8th, 2003, 06:53 PM
#2
PowerPoster
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());
}
-
Mar 9th, 2003, 04:27 AM
#3
Thread Starter
Sleep mode
-
Mar 9th, 2003, 08:29 AM
#4
Thread Starter
Sleep mode
Sorted out . It's matter of code ordering
Last edited by Pirate; Mar 9th, 2003 at 08:34 AM.
-
Mar 9th, 2003, 10:32 AM
#5
PowerPoster
What do you mean 'wont work'?
-
Mar 9th, 2003, 10:40 AM
#6
Thread Starter
Sleep mode
Originally posted by Lethal
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 !
-
Mar 9th, 2003, 11:27 AM
#7
PowerPoster
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
-
Mar 9th, 2003, 11:44 AM
#8
Thread Starter
Sleep mode
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 .
-
Mar 9th, 2003, 02:51 PM
#9
PowerPoster
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.
-
Mar 10th, 2003, 09:37 AM
#10
Member
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.
-
Mar 10th, 2003, 12:24 PM
#11
Thread Starter
Sleep mode
Thank you Iouri . That did the trick
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|