|
-
Aug 24th, 2003, 02:05 PM
#1
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.
-
Aug 24th, 2003, 07:02 PM
#2
I wonder how many charact
If you have a listbox1 , full of items and highlight an item, then click on Button1 with the following code behind it:
VB Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MessageBox.Show(ListBox1.Items(ListBox1.SelectedIndex))
End Sub
it will display the text.
-
Aug 25th, 2003, 03:30 PM
#3
Thanks, works like a charm 
Anyone got answer to my treeview?
-
Aug 25th, 2003, 03:42 PM
#4
not sure if this is what you want....
by button click >>>
VB Code:
[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
[COLOR=BLUE]If[/COLOR] [COLOR=BLUE]Not[/COLOR] TreeView1.SelectedNode [COLOR=BLUE]Is[/COLOR] [COLOR=BLUE]Nothing[/COLOR] [COLOR=BLUE]Then
[/COLOR] MessageBox.Show(TreeView1.SelectedNode.Text)
[COLOR=BLUE]End[/COLOR] [COLOR=BLUE]If
[/COLOR] [COLOR=BLUE]End[/COLOR] [COLOR=BLUE]Sub[/COLOR]
or on mouse event...
VB Code:
[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
MessageBox.Show(TreeView1.SelectedNode.Text)
[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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|