Hi,
I have a dynamically generated MenuStrip following this example:
http://www.codeproject.com/useritems..._MenuStrip.asp
Basically the menu strip allows users to save and load reports. The
Load menu is to list all the saved reports. I need to refresh the
Load menu after a new report is saved. Any help is much appreciated!
Code:
'Generates the MenuStrip, called at Form_OnLoad
Public Sub PopulateMenuStr ip()
Dim mnMenu As New MenuStrip
Dim tsItem As ToolStripMenuIt em
mnMenu.Width = 1095
mnMenu.Height = 24
tsItem = New ToolStripMenuIt em("Save", Nothing, New
System.EventHan dler(AddressOf MainMenuSave_On Click), "tsmiSave")
mnMenu.Items.Ad d(tsItem)
tsItem = New ToolStripMenuIt em("Save as Existing", Nothing,
New System.EventHan dler(AddressOf MainMenuSaveAs_ OnClick),
"tsmiSaveAs ")
UpdateSavedRepo rtList(tsItem)
mnMenu.Items.Ad d(tsItem)
tsItem = New ToolStripMenuIt em("Load", Nothing, New
System.EventHan dler(AddressOf MainMenuLoad_On Click), "tsmiLoad")
UpdateSavedRepo rtList(tsItem)
mnMenu.Items.Ad d(tsItem)
tsItem = New ToolStripMenuIt em("Delete", Nothing, New
System.EventHan dler(AddressOf MainMenuDelete_ OnClick), "tsmiDelete ")
UpdateSavedRepo rtList(tsItem)
mnMenu.Items.Ad d(tsItem)
Me.Controls.Add (mnMenu)
End Sub
'Updates the ToolStripMenuIt em based on data
'Called in above Sub (which is called OnLoad) but would also need to
cal it after anytime some1 saves a new report
'it works when the MenuStrip above is created, but how can I update
the MenuStrip above after the form has loaded
Public Sub UpdateSavedRepo rtList(ByRef sender As Object)
Dim cms As New ContextMenuStri p()
Dim sMenu() As String
Dim i As Integer
Dim sMenuRD As SqlClient.SqlDa taReader
sMenuRD = Blackport.c_Bla ckportData.getS avedFlexiReport s()
If sMenuRD.HasRows Then
ReDim Preserve sMenu(0)
i = 0
While sMenuRD.Read()
ReDim Preserve sMenu(i)
sMenu(i) = sMenuRD("txtRep ortName")
i = i + 1
End While
End If
sMenuRD.Close()
For Each sMn As String In sMenu
cms.Items.Add(s Mn, Nothing, New
System.EventHan dler(AddressOf SelectedChildMe nu_OnClick))
Next
Dim tsi As ToolStripMenuIt em = CType(sender,
ToolStripMenuIt em)
tsi.DropDown = cms
End Sub