problem adding menu item
i have db connection that loads 2 fields, name and directory
then i need to add the 2 records to a menu so i have
file.dropdownitems.add(name, nothing, process.start(directory))
but VB is telling me that system.diagnostics.process cannot be converted to system.eventhandler
what am i doing wrong can someone point me in the right direction?!
thanks in advance!!
"file.dropdownitems.add(name, nothing, process.start(directory))"
To add two records, use the .addrange method.
Here is an example:
Me.MnuFile.DropDownItems.AddRange(New System.Windows.Forms.ToolStripItem() _
{Me.MnuFileNewDatabase, Me.ToolStripSeparator5, Me.mnuFileOpen, Me.ToolStripSeparator4, _
Me.mnuFileClose, Me.ToolStripSeparator8, Me.mnuFileExplore, Me.ToolStripSeparator6, Me.MnuFileExit}) This example loads and entire menu.
edit:
ive got another problem now, when it loads from the DB it sets the directory to the same place for all of them!(the last loaded record's directory)
this is the code im using, where am i ever going wrong!?
** my on load event run the sub calldata
Private Sub RunProcess(ByVal Sender As Object, ByVal e As EventArgs)
Process.Start(appspath)
End Sub
Sub calldata()
'dim connections'
Dim MyConn As ADODB.Connection
Dim MyRecSet As ADODB.Recordset
'open connection'
MyConn = New ADODB.Connection
MyConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & startuppath & "\apps\apps.mdb;"
MyConn.Open()
'select to a recordset with SQL SELECT statement'
MyRecSet = MyConn.Execute("SELECT ID, name, Category, path FROM apps")
'get and set individual records'
Do Until MyRecSet.EOF
appsname = MyRecSet.Fields.Item("Name").Value
appscat = MyRecSet.Fields.Item("category").Value
appspath = MyRecSet.Fields.Item("path").Value
fulleditors.DropDownItems.Add(appspath, Nothing, AddressOf RunProcess)
'goto next record and then loop forever
MyRecSet.MoveNext()
Loop
'close connection at the end of the records
MyConn.Close()
End Sub
It's set up to do exactly what you describe. All of you code it not here but... appspath is set to the last read record.
Process.Start(appspath)
You should do something like this:
1.) Put in a standard event handler... this will be important
Private Sub DropDown_DropDownItemClicked(ByVal sender As Object, ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs) Handles DropDown.DropDownItemClicked2.) In your loop, add items like in this fashion:
DropDown.DropDownItems.Add(appsname
)
DropDown.DropDownItems(DropDown.DropDownItems.Count - 1).Name = appsname
DropDown.DropDownItems(DropDown.DropDownItems.Count - 1).Tag = appspath
3.) On item selection do this:
Private Sub DropDown_DropDownItemClicked(ByVal sender As Object, ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs) Handles DropDown.DropDownItemClickedProcess.Start(e.clickeditem.tag +
e.ClickedItem.Name)End SubThere ya go!
im still having troubles guys, im sorry im new to VB and im trying to learn as i got,
reneec when i tried what you said it did not even add a button on the dropdown menu
could someone please explain a little more?
sorry for being such a pain, thanks agian
lol forget i said that, i found the problem.
i always use subs for my on load event so that it stays nice and neat (ex my on_load only has 8 lines each line runs a seperate sub)
i had just forgot to add that sub into the on_load
thanks guys i got it working and it runs very smooth thank youl soooo much