CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11

Thread: menu problem

  1. #1
    Join Date
    Feb 2006
    Posts
    31

    Thumbs up menu problem

    menuitem1.Text = "Master"
    menuitem2.Text = "Sub Master"
    While reader.Read
    menuitem(j) = New MenuItem
    menuitem(j).Text = reader("vcMenuName")
    menuitem(j).MenuItems.Add(reader("vcMenuName"))
    j = j + 1
    End While
    Dim k As Integer
    mainmenu1.MenuItems.Add(menuitem1)
    Me.Menu = mainmenu1
    End Sub

    This was my code my code is running but iam using single query to get the menu dynamically , Here is my problem starts

    the menu come straight Ex(Ajeeth,Anand,Charkes,muthu,hari)
    here i need anand as sub menu under anand, i needed charkes,muthu, hari
    so this is result i need

    Thanks in advance

  2. #2
    Join Date
    Oct 2005
    Location
    Islamabad, Pakistan
    Posts
    1,277

    Re: menu problem

    these codes may help u to understand howto add menus dynamically
    code
    code
    Last edited by aniskhan; March 5th, 2006 at 03:00 PM.

  3. #3
    Join Date
    Feb 2006
    Posts
    31

    menu problem

    Hi Thanks u veryMuch,

    It is working nice, My another problems is i have said that i taking the name from database and loading the menu and giving the addhandler for click event.
    While k <= j - 1
    menuitem1.MenuItems.Add(menuitem(k))
    AddHandler menuitem(k).Click, menuitems_click
    k = k + 1
    End While

    Here i have code for each name so when click this name the code should be retrived For example

    i have muthu in the menulist and and have 02 as code in database so when im clicking the muthu i needed this 02 at EventHandler menuitems_Click
    how can i pass this code to the handler.


    Thanks in Advance

  4. #4
    Join Date
    Oct 2005
    Location
    Islamabad, Pakistan
    Posts
    1,277

    Re: menu problem

    to add event handler write like this
    Code:
    AddHandler menuitem(k).Click,AddressOf menuitems_click
    Last edited by aniskhan; March 6th, 2006 at 06:59 AM.

  5. #5
    Join Date
    Feb 2006
    Posts
    31

    Re: menu problem

    Thanks For u Reply,

    I have done this already, but this is not my problem

    See i have two fields in database Name and ID.
    Iam taking the name and id through reader. Iam retriving the id in formload
    so i want to pass this id to the EvenHandler,What can u do


    Thanks in advance

  6. #6
    Join Date
    Oct 2005
    Location
    Islamabad, Pakistan
    Posts
    1,277

    Re: menu problem

    i hope this may give u ideas
    Code:
          ' Declare an event.
        Public Event SE(ByVal id As Integer)
    
          Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim id As Integer = 20
    
            AddHandler SE, AddressOf EHandler
    
             RaiseEvent SE(id)
            'RemoveHandler SE, AddressOf EHandler
        End Sub
    
        Public Sub EHandler(ByVal Id As Integer)
            'work on id
            MessageBox.Show("Received ID " & CStr(Id))
        End Sub

  7. #7
    Join Date
    Feb 2006
    Posts
    31

    Thumbs up Menu problem

    Thank u Very Much anishKhan It is working well,

    But i cannot get the data in a collections

    See i have 12,13,14,15,16 these are the NameId In the DataBase
    and Muthu,Hari,Vinoth,Charles,Sai these are the Name in the Database

    I Got these Names in Menu Details when iam clicking the individual menu the respective Id wants to be retrieved. The code u gave was nice and it is working well but only the Last data 16 is coming for all the Names so that i cant able to get the previous id wants can i do,Pls help me

    Thanks in Advance

  8. #8
    Join Date
    Oct 2005
    Location
    Islamabad, Pakistan
    Posts
    1,277

    Re: Menu problem

    get the id on base of something u got about it .
    when u click the menu u get the menu TEXT ,u can use it to get the id from the database.
    through a query to the database
    Code:
    SELECT id FROM database WHERE Detail='MenuName'

  9. #9
    Join Date
    Feb 2006
    Posts
    31

    Thumbs up Re: menu problem

    thanks u Very much

    Finally i got the solutions by using hashtable

    I have used the think which u have said, but that is not proper a manner
    since we are taking the Name, NameId previously using a query. so we should not use another seperate query to take the same NameId

    Thank u Very Much Aniskhan

  10. #10
    Join Date
    Oct 2005
    Location
    Islamabad, Pakistan
    Posts
    1,277

    Re: menu problem

    happy that u solved the problem..
    using hashTable is also a solution.
    we can also use the dataset having the previous query results in it, u can use these to get the id.

  11. #11
    Join Date
    Feb 2006
    Posts
    31

    Re: menu problem

    hi anish using dataset is also working

    Thank u very much

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

Featured