Results 1 to 4 of 4

Thread: MenuStrip from XML

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2006
    Posts
    2

    Question MenuStrip from XML

    Is it possible to use an XML file for MenuStrip, if how?

    Like:

    <menu>

    <item1>
    <title>VBForums</title>
    <link>http://www.vbforums.com/</link>
    </item1>

    <item2>
    <title>Google</title>
    <link>http://www.google.com/</link>
    </item2>

    </menu>

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: MenuStrip from XML

    An XML file has a tree structure. A menu system has a tree structure. The two are eminently compatible, but there is no automatic correspondence as far as I'm aware. The best way to traverse a tree structure is to use recursion because a tree is inherently recursive. Your best bet would be to use a recursive algorithm to read the XML using an XmlReader or some other class intended for reading XML files, and as you read each node you create a corresponding menu item and add it to your menu.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2006
    Posts
    2

    Re: MenuStrip from XML

    I do not understand.

  4. #4
    New Member
    Join Date
    Nov 2014
    Posts
    3

    Lightbulb Re: MenuStrip from XML

    sorry for bumping very very old thread, but i'm interest with it.

    i assume this would be a browser app because the XML node has link on it ..
    using datagridview control, i've managed build menu-like datagridview and simple click handler event but without subitem support ..

    but still, i cant figure out how achieve like this with MenuStrip control ..
    any help ?


    this is my example using DataGridView ;

    XML Code ;
    Code:
    <app>
      <menu>
        <cat>1</cat>
        <title>VBForums</title>
        <link>http://www.vbforums.com/</link>
      </menu>
      <menu>
        <cat>1</cat>
        <title>Google</title>
        <link>http://www.google.com/</link>
      </menu>
    </app>
    Datagridview fill data from xml file code ;
    Code:
    Dim xFile As XmlReader
    xFile = XmlReader.Create("xml-file-path", New XmlReaderSettings)
    
    Dim ds As New DataSet
    ds.ReadXml(xFile)
    
    With dgMenu
    
       Dim dv As DataView
       
       'can set filter and sorting
       dv = New DataView(ds.Tables("menu"), "cat <> 99", "cat ASC", DataViewRowState.CurrentRows)
    
       .DataSource = dv
    
       'hide the other coloumn, so its like a vertical menu
       .Columns(0).Visible = False
       .Columns(2).Visible = False
    
    End With
    Datagridview click code ;
    Code:
    Private Sub dgMenu_CellContentDoubleClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgMenu.CellContentDoubleClick
        If sender.Rows(e.RowIndex).Cells(2).Value <> "" Then Webbrowser1.Navigate(sender.Rows(e.RowIndex).Cells(2).Value)
    End Sub

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