473,322 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Dynamically update menustrip and ToolStripMenuItem

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 PopulateMenuStrip()
Dim mnMenu As New MenuStrip
Dim tsItem As ToolStripMenuItem
mnMenu.Width = 1095
mnMenu.Height = 24
tsItem = New ToolStripMenuItem("Save", Nothing, New
System.EventHandler(AddressOf MainMenuSave_OnClick), "tsmiSave")
mnMenu.Items.Add(tsItem)
tsItem = New ToolStripMenuItem("Save as Existing", Nothing,
New System.EventHandler(AddressOf MainMenuSaveAs_OnClick),
"tsmiSaveAs")
UpdateSavedReportList(tsItem)
mnMenu.Items.Add(tsItem)
tsItem = New ToolStripMenuItem("Load", Nothing, New
System.EventHandler(AddressOf MainMenuLoad_OnClick), "tsmiLoad")
UpdateSavedReportList(tsItem)
mnMenu.Items.Add(tsItem)
tsItem = New ToolStripMenuItem("Delete", Nothing, New
System.EventHandler(AddressOf MainMenuDelete_OnClick), "tsmiDelete")
UpdateSavedReportList(tsItem)
mnMenu.Items.Add(tsItem)
Me.Controls.Add(mnMenu)
End Sub

'Updates the ToolStripMenuItem 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 UpdateSavedReportList(ByRef sender As Object)
Dim cms As New ContextMenuStrip()
Dim sMenu() As String
Dim i As Integer
Dim sMenuRD As SqlClient.SqlDataReader

sMenuRD = Blackport.c_BlackportData.getSavedFlexiReports()
If sMenuRD.HasRows Then
ReDim Preserve sMenu(0)
i = 0
While sMenuRD.Read()
ReDim Preserve sMenu(i)
sMenu(i) = sMenuRD("txtReportName")
i = i + 1
End While
End If
sMenuRD.Close()

For Each sMn As String In sMenu
cms.Items.Add(sMn, Nothing, New
System.EventHandler(AddressOf SelectedChildMenu_OnClick))
Next
Dim tsi As ToolStripMenuItem = CType(sender,
ToolStripMenuItem)
tsi.DropDown = cms
End Sub

Nov 12 '07 #1
0 4997

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: ShaneO | last post by:
Probably a stupid question, but I can't seem to find how to Enable/Disable Submenu items within a MenuStrip. File -Open -Save .. ..
12
by: Steve_Black | last post by:
I posted a similar message earlier but we've geared away from the original topic somewhat so I thought I'd post again in hopes of getting input from others. I am creating a MenuStrip...
0
by: genojoe | last post by:
Included below are four methods and a Friend that can be inserted directly into a form that already contains Button1, Button2, and MenuStrip1. Button1 populates the MainMenu control, button2...
1
by: genojoe | last post by:
I am converting from MainMenu to MenuStrip And I want to list the hierarchy of a clicked menu item. With the MainMenu, it was easy to do using the parent property of the MenuItem. With the...
6
by: Luqman | last post by:
How can I dynamically Add menuStrip and its menuItems through code using VB.Net 2005 ? Best Regards, Luqman
3
Atran
by: Atran | last post by:
Hello: I have a MenuStrip in my form, so I add a ToolStripMenuItem to the MenuStrip. The ToolStripMenuItem has a checkBox. ------------------------------------------------------------- Now, The...
3
by: MWS | last post by:
Hello, I'm trying to loop through the app.Config file and add the keys from the app.Config as MenuItems on a MenuStrip. The following line blows up... ...
1
by: Tony Johansson | last post by:
Hello! I have a System.Windows.Forms.MenuStrip with some ToolStripMenuItem. One of these ToolStripMenuItem is called saveMemberToolStripMenuItem. This one is defined like this...
2
by: Brian | last post by:
Hi, I have a menustrip that has 3 main menus and various number of menus below them... I am trying to figure out how i can loop through the main menus and then loop through each one of the main...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.