Results 1 to 4 of 4

Thread: ListBoxes and TreeViews, question

  1. #1

    Thread Starter
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    ListBoxes and TreeViews, question

    I have been searching, I've looked in my VB book and I CANNOT find anything on this, so here goes..

    How can I get the label the person clicks on in a listbox or treeview?

    Like The list box will say
    Code:
    Cookies
    People
    Cars
    When someone clicks on People, how can I actually get the string "people"? I know how to make it do something on click, but the words will be 100% different probably everytime it's loaded so I can't hard code SelectedIndices.Contains(1) to do what the string "people" would do, because it will probably be in different positions at run time depending on many different things and options.

    Erm I hope I explains that correctly.

  2. #2
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    If you have a listbox1 , full of items and highlight an item, then click on Button1 with the following code behind it:

    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         MessageBox.Show(ListBox1.Items(ListBox1.SelectedIndex))
    3. End Sub

    it will display the text.

  3. #3

    Thread Starter
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985
    Thanks, works like a charm

    Anyone got answer to my treeview?

  4. #4
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    not sure if this is what you want....
    by button click >>>
    VB Code:
    1. [COLOR=BLUE]Private[/COLOR] [COLOR=BLUE]Sub[/COLOR] Button1_Click([COLOR=BLUE]ByVal[/COLOR] sender [COLOR=BLUE]As[/COLOR] System.Object, [COLOR=BLUE]ByVal[/COLOR] e [COLOR=BLUE]As[/COLOR] System.EventArgs) [COLOR=BLUE]Handles[/COLOR] Button1.Click
    2.         [COLOR=BLUE]If[/COLOR] [COLOR=BLUE]Not[/COLOR] TreeView1.SelectedNode [COLOR=BLUE]Is[/COLOR] [COLOR=BLUE]Nothing[/COLOR] [COLOR=BLUE]Then
    3. [/COLOR]            MessageBox.Show(TreeView1.SelectedNode.Text)
    4.         [COLOR=BLUE]End[/COLOR] [COLOR=BLUE]If
    5. [/COLOR]    [COLOR=BLUE]End[/COLOR] [COLOR=BLUE]Sub[/COLOR]
    or on mouse event...
    VB Code:
    1. [COLOR=BLUE]Private[/COLOR] [COLOR=BLUE]Sub[/COLOR] TreeView1_MouseUp([COLOR=BLUE]ByVal[/COLOR] sender [COLOR=BLUE]As[/COLOR] [COLOR=BLUE]Object[/COLOR], [COLOR=BLUE]ByVal[/COLOR] e [COLOR=BLUE]As[/COLOR] System.Windows.Forms.MouseEventArgs) [COLOR=BLUE]Handles[/COLOR] TreeView1.MouseUp
    2.         MessageBox.Show(TreeView1.SelectedNode.Text)
    3.     [COLOR=BLUE]End[/COLOR] [COLOR=BLUE]Sub[/COLOR]
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

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