a cast beginner question


M

Maileen

Hi,

I have a TabControl with 2 TabPages (TabPage1 and TabPage2).
I have a TreeView control with 2 nodes (Page1 and Page2).

When i click on Page1 node, I want to display the TabPage1...the same
thing for Page2 node (TabPage2).

This is easy to do using selectedIndex = ...

But i would like to do it in another way.
Evertime that i select a node in my TreeView, i generate a AfterSelect
event. This event as an argument which is e. This argument can be used
to determine the value of selected node by using e.Node.Text.

and here starts my question. I would like to do something like that :
-----------------------
Private Sub TreeView1_AfterSelect(ByVal sender As Object, ByVal e As
System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect

TCPreferences.SelectedTab = CType("Tab" & e.Node.Text, TabPage)

End Sub
-----------------------
I know that i can not cast it like that...but I would like to keep this
"direction"...how can i do ?

Thx,
Maileen
 
Ad

Advertisements

H

Herfried K. Wagner [MVP]

Maileen said:
I have a TabControl with 2 TabPages (TabPage1 and TabPage2).
I have a TreeView control with 2 nodes (Page1 and Page2).

When i click on Page1 node, I want to display the TabPage1...the same
thing for Page2 node (TabPage2).

This is easy to do using selectedIndex = ...

But i would like to do it in another way.
Evertime that i select a node in my TreeView, i generate a AfterSelect
event. This event as an argument which is e. This argument can be used to
determine the value of selected node by using e.Node.Text.

and here starts my question. I would like to do something like that :
-----------------------
Private Sub TreeView1_AfterSelect(ByVal sender As Object, ByVal e As
System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect

TCPreferences.SelectedTab = CType("Tab" & e.Node.Text, TabPage)

Add a reference to the tab associated with a certain node to its 'Tag'
property:

\\\
Dim n As TreeNode = ...
n.Tag = Me.TabPage1
....
///

In the 'AfterSelect' event handler, you can use this code to select the
associated tab:

\\\
Me.TabControl1.SelectedTab = DirectCast(e.Node.Tag, TabPage)
///
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top