Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I get a user clicked on collection index number?

Status
Not open for further replies.

emaduddeen

Programmer
Mar 22, 2007
184
US
Hi Everyone,

I would like to get the index number of a tab collection when the user clicks on a tab. I already have a click event in place.

Here is what I tried so far:

Code:
    Private Sub Ribbon1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Ribbon1.Click
        MessageBox.Show("You clicked on:" & Ribbon1.Tabs.Item(1).ToString)
    End Sub

This is almost what I am looking for but I need a way to change the (1) to whatever index number is returned when the user clicks on a tab.

Thanks.

Truly,
Emad
 
Code:
    Private Sub Ribbon1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Ribbon1.Click
        Dim tbctrl As TabControl = CType(sender, TabControl)
        Dim CurrentTab As TabPage = tbctrl.SelectedTab

        MessageBox.Show("You clicked on:" & CurrentTab.Text)
    End Sub

-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
 
Hi Sorwen,

Thanks for the reply.

It did not work maybe because I'm using an open source ribbon control and after I did a messagebox to see what sender had it showed sender=System.Windows.Forms.Ribbon which comes from that open source control. It gave me a casting error.

Is there something I can use to get the current index for the tab the user clicks on? I am also assuming tabs in this ribbon control are different then a regular tab control. From what I see, the tabs are defined on the ribbon properties as a collection but I don't know how to work with collections.

Truly,
Emad
 
Hi,

I think I need to re-word my question. Sorry for any confusion my previous question may have presented.

If there are 5 controls on a form and they are in a collection, how do I get the index number of the control that the user clicks on?

Truly,
Emad
 
Hi Sorwen,

Thanks for the reply.

It did not work maybe because I'm using an open source ribbon control and after I did a messagebox to see what sender had it showed sender=System.Windows.Forms.Ribbon which comes from that open source control. It gave me a casting error.

Is there something I can use to get the current index for the tab the user clicks on? I am also assuming tabs in this ribbon control are different then a regular tab control. From what I see, the tabs are defined on the ribbon properties as a collection but I don't know how to work with collections.

Truly,
Emad
Ah, I thought that Ribbon what just what you named it. No clue then that is going to be specific to the control. Put a break in there and look at what information is passed by the sender or e event argument. maybe see if individual tabs have a click event? If it is a decent control it should have some way of telling you which was selected. Really I suggest contacting the vendor of the control or seeing if they have a forum.



Hi,

I think I need to re-word my question. Sorry for any confusion my previous question may have presented.

If there are 5 controls on a form and they are in a collection, how do I get the index number of the control that the user clicks on?

Truly,
Emad
It doesn't work like that. There is no default connection require by vb.net that says an event and a collect have to correlate.

For example when you said a tab I assumed you were working with a tab control. That is the example I gave you. There neither the sender nor the event argument contain the tab clicked. What the is passed is the sender which is the TabControl and what it however does do is track the current TabControl that should be selected(visible). This is simply the function of a properly created control/event, but it isn't automatic.

Someone else here might happen to have the some open source control you have and might be able to better answer your question.



-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top