C# How to make one item from Menustrip be default selected? How to display the selected items from Menustrip Selected to a textbox

StackOverflow https://stackoverflow.com/questions/16793685

  •  30-05-2022
  •  | 
  •  

Domanda

I am working on C# WFA. I have one menustrip which has one item called: Settings, under this I have three items: ID, Number, and Time. Under Number item there has 5 items again which man can choose. Now I want to make it like this: first make one of the items under Number is default chosen, Secondly, I want to have one more textbox in the GUI, which will show which item is selected under number.

For example:

       Settings

               ---ID

                ---Number

                    ----NUMBER1

                    ----Number 2

                    ----Number 3    

               ---Time

So I want to set the Number 2 as the default chosen item, how can I do that? I want to display the selected Number item in textbox when one is selected, How can I do that?

Thanks a lot!

BR Emma

È stato utile?

Soluzione

For Select NUMBER 2 as BY Default you have to add single line in your code,

this.NUMBER2ToolStripMenuItem.Select();

This code for getting text of selected items...

' your method would look something like this

Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

Dim mnuItem As MenuItem = DirectCast(sender, MenuItem)

MessageBox.Show(mnuItem.Text)

End Sub '

' and just so you know, it would be attached to the event like so

AddHandler MenuItem2.Click, AddressOf MenuItem2_Click

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top