PC Review


Reply
Thread Tools Rate Thread

comboBox TextChanged event fires twice because Items.Insert() fires the event too...

 
 
Rob Hindman
Guest
Posts: n/a
 
      22nd Aug 2003
Hi, I have a simple windows form, with two ComboBox controls (and
several other controls). For both of the comboBox controls,
DropDownStyle=DropDown.
For some reason that I can't figure out, when the user pastes text
into the comboBox, the event fires twice. At first I didn't notice
this, but once I added error checking, I started seeing my error
twice. Here some example code:

private void comboBox_doit_TextChanged(object sender, System.EventArgs
e)
{
...
comboBox_doit.Items.Insert(1,comboBox_doit.Text);
...
}

Does anyone know how to prevent the second event from firing? I have
tried using BeginUpdate() & EndUpdate() around Items.Insert(), I have
tried using a simple bool semaphore, I have even tried unregistering
the event before calling Items.Insert(), and then adding a new event
handler after it...

I also can not figure out why this only happens to one of my
comboBoxes, and not the other one... Hmmm...

Alas, I am stuck... I would be grateful for any comments, suggestions,
or advice...
Many Thanks,
-Rob.
 
Reply With Quote
 
 
 
 
Lion Shi
Guest
Posts: n/a
 
      25th Aug 2003
Hello Rob,

There is no problem with the sample code you paste. I think the reason
should be other code in the project. Could you please paste more code to
reproduce the issue, and I'd like to help you troubleshooting it.

Best regards,

Lion Shi [MSFT]
MCSE, MCSD
Microsoft Support Engineer
Get Secure! ¨C www.microsoft.com/security

This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use. 2003 Microsoft Corporation. All rights
reserved.
--------------------
| From: (E-Mail Removed) (Rob Hindman)
| Newsgroups: microsoft.public.dotnet.framework.windowsforms
| Subject: comboBox TextChanged event fires twice because Items.Insert()
fires the event too...
| Date: 22 Aug 2003 13:45:38 -0700
| Organization: http://groups.google.com/
| Lines: 29
| Message-ID: <(E-Mail Removed)>
| NNTP-Posting-Host: 131.107.3.86
| Content-Type: text/plain; charset=ISO-8859-1
| Content-Transfer-Encoding: 8bit
| X-Trace: posting.google.com 1061585140 13270 127.0.0.1 (22 Aug 2003
20:45:40 GMT)
| X-Complaints-To: groups-(E-Mail Removed)
| NNTP-Posting-Date: 22 Aug 2003 20:45:40 GMT
| Path:
cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed00.sul.t-online.de!t-onlin
e.de!npeer.de.kpn-eurorings.net!news-out.nuthinbutnews.com!propagator2-sterl
ing!news-in-sterling.newsfeed.com!tdsnet-transit!newspeer.tds.net!sn-xit-02!
sn-xit-06!sn-xit-09!supernews.com!postnews1.google.com!not-for-mail
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.windowsforms:50793
| X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms
|
| Hi, I have a simple windows form, with two ComboBox controls (and
| several other controls). For both of the comboBox controls,
| DropDownStyle=DropDown.
| For some reason that I can't figure out, when the user pastes text
| into the comboBox, the event fires twice. At first I didn't notice
| this, but once I added error checking, I started seeing my error
| twice. Here some example code:
|
| private void comboBox_doit_TextChanged(object sender, System.EventArgs
| e)
| {
| ...
| comboBox_doit.Items.Insert(1,comboBox_doit.Text);
| ...
| }
|
| Does anyone know how to prevent the second event from firing? I have
| tried using BeginUpdate() & EndUpdate() around Items.Insert(), I have
| tried using a simple bool semaphore, I have even tried unregistering
| the event before calling Items.Insert(), and then adding a new event
| handler after it...
|
| I also can not figure out why this only happens to one of my
| comboBoxes, and not the other one... Hmmm...
|
| Alas, I am stuck... I would be grateful for any comments, suggestions,
| or advice...
| Many Thanks,
| -Rob.
|

 
Reply With Quote
 
Lion Shi
Guest
Posts: n/a
 
      25th Aug 2003
Hello Rob,

Further more, I don't think the TextChanged event is fired by the Insert
method. If so, the event will be fired recursively, untill the stack
overflows. Hence the problem should be other code.

Best regards,

Lion Shi [MSFT]
MCSE, MCSD
Microsoft Support Engineer
Get Secure! ¨C www.microsoft.com/security

This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use. 2003 Microsoft Corporation. All rights
reserved.
--------------------
| From: (E-Mail Removed) (Rob Hindman)
| Newsgroups: microsoft.public.dotnet.framework.windowsforms
| Subject: comboBox TextChanged event fires twice because Items.Insert()
fires the event too...
| Date: 22 Aug 2003 13:45:38 -0700
| Organization: http://groups.google.com/
| Lines: 29
| Message-ID: <(E-Mail Removed)>
| NNTP-Posting-Host: 131.107.3.86
| Content-Type: text/plain; charset=ISO-8859-1
| Content-Transfer-Encoding: 8bit
| X-Trace: posting.google.com 1061585140 13270 127.0.0.1 (22 Aug 2003
20:45:40 GMT)
| X-Complaints-To: groups-(E-Mail Removed)
| NNTP-Posting-Date: 22 Aug 2003 20:45:40 GMT
| Path:
cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed00.sul.t-online.de!t-onlin
e.de!npeer.de.kpn-eurorings.net!news-out.nuthinbutnews.com!propagator2-sterl
ing!news-in-sterling.newsfeed.com!tdsnet-transit!newspeer.tds.net!sn-xit-02!
sn-xit-06!sn-xit-09!supernews.com!postnews1.google.com!not-for-mail
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.windowsforms:50793
| X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms
|
| Hi, I have a simple windows form, with two ComboBox controls (and
| several other controls). For both of the comboBox controls,
| DropDownStyle=DropDown.
| For some reason that I can't figure out, when the user pastes text
| into the comboBox, the event fires twice. At first I didn't notice
| this, but once I added error checking, I started seeing my error
| twice. Here some example code:
|
| private void comboBox_doit_TextChanged(object sender, System.EventArgs
| e)
| {
| ...
| comboBox_doit.Items.Insert(1,comboBox_doit.Text);
| ...
| }
|
| Does anyone know how to prevent the second event from firing? I have
| tried using BeginUpdate() & EndUpdate() around Items.Insert(), I have
| tried using a simple bool semaphore, I have even tried unregistering
| the event before calling Items.Insert(), and then adding a new event
| handler after it...
|
| I also can not figure out why this only happens to one of my
| comboBoxes, and not the other one... Hmmm...
|
| Alas, I am stuck... I would be grateful for any comments, suggestions,
| or advice...
| Many Thanks,
| -Rob.
|

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ComboBox MouseDoubleClick Event Never Fires senfo Microsoft C# .NET 4 18th Sep 2006 06:59 PM
ComboBox SelectionChangeCommitted event fires twice docw@globetrotter.net Microsoft VB .NET 5 20th Jul 2006 12:31 PM
RE: Textchanged event fires on every post =?Utf-8?B?RXRoZW0gQXp1bg==?= Microsoft ASP .NET 0 18th Jan 2005 05:41 PM
Textchanged event fires on every post =?Utf-8?B?U2FtdWVsIENoYW4=?= Microsoft ADO .NET 0 18th Jan 2005 07:01 AM
Selecting a combobox item when textchanged event fires... Greg Allen Microsoft Dot NET Framework Forms 0 30th Aug 2004 12:41 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:51 AM.