473,320 Members | 1,722 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,320 software developers and data experts.

events problem

Hello,
I am trying to react to a selection change in a combobox which is
filled dynamicly during the run of the program.
I am trying to do the following:
1)Declaring the comboBox
2)Initializing it (it is empty).
3)Filling it with data
private void Fill_Menu()
{
for(int i=0;i<command_name.Count;i++)
{
comboBox.Items.Add(command_name[i]);
}
}

And than inside some other function I am doing the:
this.comboBox.SelectedIndexChanged+=new
EventHandler(comboBox_SelectedIndexChanged);

but the problem is that it activates the event more times than needed
and I understood that I have to put this event inside the OnLoad of
the form function but the problem is that I have no data inside the
combobox at the begginig .How do I solve this problem?
Thank you!
Nov 16 '05 #1
2 1232
yyy
You can check wether the combo box is full or not this way:

void comboBox_SelectedIndexChanged(...)
{
if(this.comboBox1.Items.Count > 0)
{
..
..
..
}
}
*---------------------------------*
Posted at: http://www.GroupSrv.com
*---------------------------------*

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Nov 16 '05 #2
You can use a flag to indicate when you're filling the combo box and
the resulting SelectedIndexChanged events are of no interest to you:

private void Fill_Menu()
{
this.fillingComboBox = true;
for(int i=0;i<command_name.Count;i++)
{
comboBox.Items.Add(command_name[i]);
}
this.fillingComboBox = false;
}

private void comboBox_SelectedIndexChanged(object sender, EventArgs ea)
{
if (!this.fillingComboBox)
{
....react to selected index changed event here...
}
}

Another possible choice is that you could remove/add the event handler
in your fill method:

private void Fill_Menu()
{
this.comboBox.SelectedIndexChanged -= new
EventHandler(comboBox_SelectedIndexChanged);
for(int i=0;i<command_name.Count;i++)
{
comboBox.Items.Add(command_name[i]);
}
this.comboBox.SelectedIndexChanged += new
EventHandler(comboBox_SelectedIndexChanged);
}

Nov 16 '05 #3

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

Similar topics

0
by: Steven Brown | last post by:
I'm trying to figure out how to safely use .NET events/delegates in a thread-safe class. There are a couple problems. One is that the standard "if(EventName != null) EventName(...);" call can...
5
by: knocte | last post by:
Hello. I am a web developer very worried about "bloat code" and "languages mixture". So, since some time, I always try to avoid completely the use of javascript in XHTML/HTML files. This leads...
2
by: Jon Davis | last post by:
The garbage handler in the .NET framework is handy. When objects fall out of scope, they are automatically destroyed, and the programmer doesn't have to worry about deallocating the memory space...
0
by: Efim | last post by:
Hi, I have got some problem with sending of events in .NET. I am using remouting. The client has got 2 objects for receiving different types of events (responses and events) The server has got...
12
by: scsharma | last post by:
Hi, I am working on creating a webapplication and my design calls for creating main webform which will have menu bar on left hand side and a IFrame which will contain all the forms that are shown...
2
by: hakan_cn | last post by:
Hi all! Sorry for the cross-post, I really have a difficult problem and need some help badly. I have a VB6 ActiveX component (dll) that listens to a real-time data feed of stock quotes (built...
30
by: Burkhard | last post by:
Hi, I am new to C# (with long year experience in C++) and I am a bit confused by the language construct of events. What is it I can do with events that I cannot do with delegates? At the moment...
5
by: Paal Berggreen | last post by:
I am involved with development of a Portal solution using ASP.NET 2.0 and WebParts. The WebParts framework use the default personalization providers, and the personalization data thus ends up in...
3
by: daan | last post by:
Hello, I have a problem and I can't get the solution for it :( I have a com dll, which i imported as a reference. The com object is part of a class which is multithreaded and will create...
0
by: hmm | last post by:
Hi all I have two problems: Problem #1: I'm using a .NET Form with the property 'FormBorderStyle' set to 'None'. The idea is to completely cover the area of that Form with a UserControl. In...
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...
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: 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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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.