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

Thread: Vector Class

  1. #1
    Join Date
    Jul 1999
    Location
    India.
    Posts
    81

    Vector Class

    I have a vector class object in which I have stoted Strings.
    Can I convert it into MenuItem objects?(some casting)
    If I can ,then how?


  2. #2
    Join Date
    Mar 2000
    Location
    Dublin, Ireland
    Posts
    124

    Re: Vector Class

    Monika,

    The following code snippet should do the trick://Create your vector object and fill it with Strings
    Vector myVector = new Vector(1);
    myVector.addElement("New");
    myVector.addElement("Open");
    myVector.addElement("Save");
    myVector.addElement("Save As...");
    //create your Menu that will hold your MenuItems
    Menu fileMenu = new Menu("File");
    //now add MenuItems to the Menu, giving the
    //Strings from the Vector as the label...
    for ( int index = 0 ; index < myVector.size() ; index++ )
    fileMenu.add(new MenuItem((String)myVector.elementAt(index)));

    And that's it!

    Hope this helps.

    Regards,
    dogBear



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