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>
Printable View
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>
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.
I do not understand.
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 ;
Datagridview fill data from xml file 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 click 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
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