I've been trying to figure out the easiest way to populate a menu to allow for easy updating in the future. I would like to add anything to a specific folder and when the program runs it would be populated by the contents of the specific folder.
Is this possible? What should I look into to do this? Not sure of the process to use to do this, that is if it is even possible.
See if this helps to add DropDownItems or Items to a menu.
1 MenuStrip(with a "File" menu item)
Public Class Form1 Private myCoolFolder As String = "C:\" Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load For Each myFile In My.Computer.FileSystem.GetFiles(myCoolFolder, FileIO.SearchOption.SearchTopLevelOnly, "*.*") '// get files. FileToolStripMenuItem.DropDownItems.Add(myFile) '// add as DropDownItems. ' MenuStrip1.Items.Add(myFile)'// add as Category on Menu. Next End Sub End Class
Edited by codeorder: n/a
Thanks for the pointing in the general direction. I'm going to post my code below for anyone else that might need help with this also. The files are going to be .ini's that I'm scanning. Is there a way to put comments in the .ini's that the reader will ignore?
'LOAD Toolbox Menu Private Sub LoadToolboxMenu() 'Load Initial Folders 'Looks for toolboxCats.ini Dim File_Name As String = Application.StartupPath & "\toolbox\toolboxcats.ini" If System.IO.File.Exists(File_Name) = True Then Dim objReader As New System.IO.StreamReader(File_Name) Do While objReader.Peek() <> -1 ToolStripDropDownButton1.DropDownItems.Add(objReader.ReadLine()) Loop End If 'Load Base Folders For Each myFile In My.Computer.FileSystem.GetFiles(ToolboxScanFolder, FileIO.SearchOption.SearchAllSubDirectories, "toolbox.ini") Next End Sub
I want to be able to have the following information stored in my .ini files and then pull it as needed.
- Application Name
- Application Path to EXE
>>Is there a way to put comments in the .ini's that the reader will ignore?
I believe that comment lines for a .ini file start with ";".
[category title 1] ;Documentation=kewl Application Name=VS Professional Application Path to EXE=C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe Description=Software developing product [category title 2] ;Documentation=kewl also Application Name=Firefox Application Path to EXE=C:\Program Files (x86)\Mozilla Firefox\firefox.exe Description=Web browser of choice
I would load the file in a String Array and loop thru lines.
See if this helps for adding items with .Click Event and ToolTipText to a ToolStripDropDownButton.
Public Class Form1 Private myIniFile As String = "C:\test.ini" '// your File. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If IO.File.Exists(myIniFile) Then Dim arTemp() As String = IO.File.ReadAllLines(myIniFile) '// load lines as arrays. For i As Integer = 0 To arTemp.Length - 1 '// loop thru lines. '// check for lines like: [category title 1] If arTemp(i).StartsWith("[") Then '// once located, you know the next 4 lines are for that category. '// line 2 in category. Dim mItem As New ToolStripMenuItem(arTemp(i + 2).Substring(arTemp(i + 2).IndexOf("=") + 1)) '// add .Text of item. '// line 3 in category. mItem.Tag = arTemp(i + 3).Substring(arTemp(i + 3).IndexOf("=") + 1) '// add FullPath to .Tag. '// line 4 in category. mItem.ToolTipText = arTemp(i + 4).Substring(arTemp(i + 4).IndexOf("=") + 1) '// add Description as ToolTipText. AddHandler mItem.Click, AddressOf myCoolDropDownItems_Click '// give the DropDownItem an Event to handle. ToolStripDropDownButton1.DropDownItems.Add(mItem) '// add item to DropDownButton. End If Next End If End Sub Private Sub myCoolDropDownItems_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Process.Start(CType(sender, ToolStripMenuItem).Tag.ToString) '// use FullPath from .Tag to load app.. End Sub End Class
Edited by codeorder: n/a
Okay, so I'm finally understanding how the Form1_Load(). I would like to categorize the items in the list. I would like to make it to where anyone can change the categories in the list without having to have access to the source code. Is this a dumb idea?? I know I would have to add another look to the above code to add the mItem to the correct section.
>> I would like to categorize the items in the list. I would like to make it to where anyone can change the categories in the list without having to have access to the source code.
What about adding a ContextMenu to the item with a "Edit Item" option that loads a Form and allows you to edit the item.Text, .Tag, .etc.?
I think I'm a little loss with the ContextMenu.
I currently have this code that is loading a category list to my ProgramsToolStripMenuItem based off of a .ini file that anyone can modify.
'Load Initial Folders 'Looks for toolboxCats.ini Dim File_Name As String = Application.StartupPath & "\toolbox\Programs\toolboxcats.ini" If System.IO.File.Exists(File_Name) = True Then Dim objReader As New System.IO.StreamReader(File_Name) Do While objReader.Peek() <> -1 ToolStripMenuItem1.DropDownItems.Add(objReader.ReadLine()) Loop End If
how can i auto sum the values in datagrid cells of the same row in vb.net
I have been trying to figure this out for hours with no avail. Basically I need to print out user input as Initial value, ASCII(char), ASCII(int), and Hex. I ...