473,324 Members | 2,356 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,324 software developers and data experts.

Problem adding menuitem

When I run the following code through on the first round, my sub-menu
(branched off mnuOpenPorts menuitem) shows a nice list of ports.
When it gets run through on the 2nd pass, the sub menu indicates that it
should be there but there's no items appearing in it. (ie a small indicator
arrow is there showing there should be a sub menu but nothing pops up)
When I step through the code, I have 5 items in Comports. After adding all
the sub menu items, all 5 appear to be listed in mnuOpenPorts.MenuItems
Any ideas what I'm doing wrong?
thanks

/// Adds a submenu item for each available serial port showing current
status
private void TestComports()
{
MenuItem item;
string str;
int idx = 0;
// Clear old sub menu
mnuOpenPort.MenuItems.Clear();

// Show items in the list box
for (int nCount = 0; nCount < Comports.Count; nCount++)
{
Sax.Communications.SerialOptions Options = new
Sax.Communications.SerialOptions(SerConn.Options);
Options.PortName = Comports[nCount];
// Set the options
SerConn.SetOptions(Options);
if ((m_CommunicationManager.SerialConnected)
&& (m_CommunicationManager.SerialPortName == Comports[nCount]))
{
// add menu item saying this is the connected port
str = string.Format("{0} (Open)", (string)Comports[nCount]);
lstPorts.Items.Add(str);

//Create new menu item
item = new MenuItem(str);
item.Checked = true;
item.Click += new EventHandler(cmdConnect_Click);
//Add item to the submenu
mnuOpenPort.MenuItems.Add(item);
}
else
{
str = "";
// Test ports will open. If they open OK then close them again
try
{
SerConn.Open();
str = string.Format("{0} (Closed)", (string)Comports[nCount]);
}
catch(System.IO.IOException)
{
str = string.Format("{0} (Not available)", (string)Comports[nCount]);
}
finally
{
try
{
if (SerConn.IsOpen)SerConn.Close();
}
catch
{
}
}
// Add new item to submenu
lstPorts.Items.Add(str);
item = new MenuItem(str);
item.Click += new EventHandler(cmdConnect_Click);
mnuOpenPort.MenuItems.Add(item);
}
}
}
Nov 16 '05 #1
0 1363

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

Similar topics

8
by: filip stas | last post by:
How do i add references during runtime?
0
by: Deutsche Dogge | last post by:
Hi. I'M having a weird problem with addign menuitems to a menu dynamically on the popup event of the menuitem containing the container of the menuitems i wanna add (tools -> external -> {list of...
4
by: Claire | last post by:
Sorry Ive added this twice (sortof) but if I'd added an addendum to the first one then this would probably have been ignored. This problem affects a ContextMenu attached to a NotifyIcon object. I...
4
by: Eric Sabine | last post by:
I've simplified the code to the following. I'm just overlooking something very simple I'm sure. Dim mic() As MenuItem mic = New MenuItem(3) {} mic(0) = New MenuItem("a") mic(0).Index = 1 ...
0
by: ZH | last post by:
Hi There, I have an application that runs from the systray. When the user right clicks on the icon it shows the user a list of of menu items. That works without a problem. The problem is...
2
by: Miky | last post by:
Hi, I'm looking resources or tutorial where I can learn how to add properties to other objects at design time for VB.NEt or C#. I want to reproduce the same effect as when your drop the...
2
by: **Developer** | last post by:
I've been asking about a Menu problem I have without results. So here is a test case I've developed that shows the problem. Simply create a soultion with one project containg one form and...
0
by: Jeff | last post by:
hey asp.net 2.0 I want to add a menu item to a menu on my webpage programatically. I've tryed using the code below, but it doesn't add the menu item to the menu. MenuItem menuItem = new...
1
by: Neverhood | last post by:
Hi folks, I'm trying to make a small game about being a drug dealer, with a 10x8 grid JPanel. On top of that i have another 10x8 grid JPanel as glassPane for the player icon. I have all the...
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...
1
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...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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.