Results 1 to 2 of 2

Thread: Context menu item Dynamic naming.

  1. #1

    Thread Starter
    Lively Member smilbuta's Avatar
    Join Date
    Apr 2005
    Location
    Orlando
    Posts
    104

    Context menu item Dynamic naming.

    Greetings.
    I wish to name the items in a contex menu strip dynamicaly.
    Im unsure how to explain the problem but ill show my code and hopefully those of you with deep VB know wots will see my problem.


    THIS IS MY CURRENT CODE: Menu item 1 and 2 are reading the name from an array of names and those names are being assigned to each Menu item in turn.
    VB Code:
    1. Private Sub trayMenuItems()
    2.         Dim len As Integer
    3.         Dim i As Integer
    4.         Dim s As String
    5.         len = (AStatus.Count) - 1
    6.         For i = 0 To len
    7.             s = AStatus(i)
    8.         Next
    9.         MenuItem1.Text = AStatus(0)
    10.         MenuItem2.Text = AStatus(1)
    11.     End Sub

    THIS IS WHAT I WANT TO DO:
    VB Code:
    1. Private Sub trayMenuItems()
    2.         Dim len As Integer
    3.         Dim i As Integer
    4.         Dim s As String
    5.         len = (AStatus.Count) - 1
    6.         For i = 0 To len
    7.             s = AStatus(i)
    8.             [B]MenuItem &  i +1 & .Text = AStatus(i)[/B]
    9.         Next
    10.     End Sub
    The bold is what im attempting to do. THe code there is wrong and does not work. The problem is im not sure i can do waht i want to do because im actualy trying to place a variable in an objects name...sorry i cant be more descriptive.. (read VB novice)??

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: Context menu item Dynamic naming.

    You can do something like this:
    VB Code:
    1. Dim AStatus() As String = New String() {"abc", "def", "ghi"}
    2.         Dim mnuItm As ToolStripItemCollection = ContextMenuStrip1.Items()
    3.         For i As Integer = 0 To mnuItm.Count - 1
    4.             mnuItm(i).Text = AStatus(i) 'Just make sure that you don't get out of bound on AStatus array
    5.         Next

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width