Iceman5 Posted August 14, 2003 Posted August 14, 2003 Hello there... I got a small problem. I need to know which of the submenus the user clicks on. It´s not hard if I wouldn´t need to create x number of submenus in the code. The thing is that the user decides how many submenus there will be so I need to run the same function when clicked on a submenu Is there a way to see which submenu the user clicked on? Or get the text of the clicked submenu or the name of the clicked submenu? Thanks alot //Martin Andersson Code: Private Sub Create_Usermenulist() Dim rows, i As Integer 'Empty the dataset DS_User2.Clear() 'Filling it OleDbDataAdapter2.Fill(DS_User2) 'Clears the menu Menu_Users.MenuItems.Clear() 'Coputing number of lines rows = DS_User2.User.Rows.Count 'Adding the menus For i = 0 To rows - 1 'Declare a new submenu Dim menu_users_selected_row As New MenuItem(i) 'Set the text to the selected item in the datagrid menu_users_selected_row.Text = DG_User.Item(i, 0) 'Add the submenu under the "Menu_Users" Menu_Users.MenuItems.Add(menu_users_selected_row) 'addhandler decided when to trigger the function 'adressof which function is triggered AddHandler menu_users_selected_row.Click, AddressOf Me.Menu_Users_Selected_Row_Click Next 'Sets the user variabel Try user = DG_User.Item(DG_User.CurrentRowIndex, 0) Catch End Try DG_Module.CaptionText = "Användare: " + user End Sub Private Sub Menu_Users_Selected_Row_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Menu_Edit_User.Click 'Want to know which submenu that is clicked on End Sub Quote
Administrators PlausiblyDamp Posted August 14, 2003 Administrators Posted August 14, 2003 Private Sub Menu_Users_Selected_Row_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Menu_Edit_User.Click 'Want to know which submenu that is clicked on Dim m As MenuItem m = DirectCast(sender, MenuItem) 'Can now access m.Index or m.Text to identify menu item End Sub Hope that is of some use. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Iceman5 Posted August 14, 2003 Author Posted August 14, 2003 Ohhh... Thanks alot. That solved everything. *bows* //Martin Andersson Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.