Results 1 to 11 of 11

Thread: selected item in listbox ??[Resolved]

  1. #1

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083

    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.

  2. #2
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    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());
    }

  3. #3

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083

    Unhappy

    this won't work .

  4. #4

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Sorted out . It's matter of code ordering
    Last edited by Pirate; Mar 9th, 2003 at 08:34 AM.

  5. #5
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    What do you mean 'wont work'?

  6. #6

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    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 !

  7. #7
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    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

  8. #8

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    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 .

  9. #9
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    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.

  10. #10
    Member
    Join Date
    Dec 2002
    Location
    NY, USA
    Posts
    52
    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.
    Iouri Boutchkine

  11. #11

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    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
  •  



Click Here to Expand Forum to Full Width