Question : add MRU List o Contextmenustrip in vb.net

Hi Experts,
My Windows desktop application has menu to open database files. I want to display 5 most recently used files as a contextmenustrip items. I have code to add it as a File Menu Item. But i am not using any menus. It is all graphical with big buttons and the button has contextmenustrip attached to it. How do I read these MRU files names and assign them dynamically to contextmenustrip? I am using Visual Studio 2008.
I will appreciat your help.
Thank you

Answer : add MRU List o Contextmenustrip in vb.net


Dim MRUListArray As Array = Nothing
'populate your array here then
Dim MRUContextMenuStrip As New ContextMenuStrip
For i = 1 To 5
If MRUListArray(i) <> "" Then
MRUContextMenuStrip.Items.Add(MRUListArray(i))
End If
Next
AddHandler MRUContextMenuStrip.ItemClicked, AddressOf sButton1


Private Sub sButton1(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim sItem = DirectCast(sender, ContextMenuStrip)
'now you can get the value of the item clicked by
File.Open(sItem.Text, FileMode.Open)
'or
File.Open(sItem.Name, FileMode.Open)
'depending on where you saved the full path
End Sub

Random Solutions  
 
programming4us programming4us