Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ComboBox.DataSource fires SelectedValueChanged event

10 views
Skip to first unread message

Shawn

unread,
May 20, 2003, 10:16:40 AM5/20/03
to
I'm populating the ComboBox in my Form_Load method and the
SelectedValueChanged event fires according to how many items are added. I
want the event to fire when the user changes the value of the ComboBox, not
when it's being populated. What should I do?

Thanks,
Shawn


Matt Gertz

unread,
May 20, 2003, 3:43:03 PM5/20/03
to
Shawn,
I've been trying to repro your experience (on VS 2003) but unfortunately
without luck. I've had similar issues in occasionally involving other
events, which I worked around by simply ignoring the offending events
during the form load -- there are a couple of ways to do this, but the
simplest is to just check the status of some initialization variable you
define.

I'd be happy to look into this further, but I'd need to see your form_load
and InitializeComponent methods to determine anything more.

--Matt Gertz--*
VB
--------------------
> From: "Shawn" <bossm...@hotmail.com>
> Subject: ComboBox.DataSource fires SelectedValueChanged event
> Date: Tue, 20 May 2003 16:16:40 +0200
> Lines: 9
> X-Priority: 3
> X-MSMail-Priority: Normal
> X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
> X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
> Message-ID: <u9R2wpt...@TK2MSFTNGP11.phx.gbl>
> Newsgroups: microsoft.public.dotnet.languages.vb
> NNTP-Posting-Host: pc4.akermaritime.no 193.161.152.244
> Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.phx.gbl
> Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:108894
> X-Tomcat-NG: microsoft.public.dotnet.languages.vb

Matt Gertz

unread,
May 21, 2003, 3:44:15 PM5/21/03
to
Hi, Shawn,
OK, I see what you're seeing now. I was using "Add" to add values to the
combo box, not "DataSource." Using "Add" doesn't cause the event to fire,
because using "Add" doesn't change the value of what's in the combo box's
edit box -- it leaves the edit box part alone. (In fact, the edit box ends
up being blank if nothing was already in it.) However, using "Datasource"
*does* change the value of the edit box -- incoming entries affect the
selected value, until the last one, where it resets to the first item for
the selection. I do not see any way to turn this behavior off, short of
turning off the event handling or ignoring the event. Of course, you could
iterate over the data itself and use "Add" to add values to the combobox,
but it's probably cheaper to ignore the event during initialization, unless
performance gets to be an issue due to all of those events.

Sorry I couldn't be of more help. :-( If you like, I could file a bug
against the appropriate team to investigate a possible change for future
versions, since I agree that this is less than desirable behavior. (A
change is probably not likely, though, since there are folks who probably
have code that relies on the current behavior -- they might want to
"massage" entries after they get added to the list, etc.)

--Matt Gertz--*
VB
--------------------
> From: "Shawn" <bossm...@hotmail.com>

> References: <u9R2wpt...@TK2MSFTNGP11.phx.gbl>
<yQbyzfwH...@cpmsftngxa06.phx.gbl>
> Subject: Re: ComboBox.DataSource fires SelectedValueChanged event
> Date: Wed, 21 May 2003 11:29:59 +0200
> Lines: 119


> X-Priority: 3
> X-MSMail-Priority: Normal
> X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
> X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106

> Message-ID: <elHIOu3H...@tk2msftngp13.phx.gbl>


> Newsgroups: microsoft.public.dotnet.languages.vb
> NNTP-Posting-Host: pc4.akermaritime.no 193.161.152.244
> Path:

cpmsftngxa06.phx.gbl!TK2MSFTNGXA06.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP0
8.phx.gbl!tk2msftngp13.phx.gbl
> Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:109126
> X-Tomcat-NG: microsoft.public.dotnet.languages.vb
>
> Hi Matt. Thanks for helping me here. I could do as you suggest and ignore
> the event until I initialize a variable, but I'm hoping there is another
> solution to the problem. I'm attaching the vb file for you to have a look
> at.
>
> Shawn
>
>
>
> "Matt Gertz" <mat...@online.microsoft.com> wrote in message
> news:yQbyzfwH...@cpmsftngxa06.phx.gbl...

Shawn

unread,
May 21, 2003, 5:02:46 PM5/21/03
to
Hi Matt. I see the problem with code that relies on the current behavior,
but maybe in the future it could be optional? Well, anyway it's not a big
deal..

Thanks for your help!

Shawn

"Matt Gertz" <mat...@online.microsoft.com> wrote in message

news:1EmqOF9H...@cpmsftngxa06.phx.gbl...

Matt Gertz

unread,
May 23, 2003, 3:23:59 PM5/23/03
to
I've filed a bug to track this suggestion. Thanks, Shawn!

--------------------
> From: "Shawn" <bossm...@hotmail.com>
> References: <u9R2wpt...@TK2MSFTNGP11.phx.gbl>
<yQbyzfwH...@cpmsftngxa06.phx.gbl>
<elHIOu3H...@tk2msftngp13.phx.gbl>
<1EmqOF9H...@cpmsftngxa06.phx.gbl>

> Subject: Re: ComboBox.DataSource fires SelectedValueChanged event
> Date: Wed, 21 May 2003 23:02:46 +0200
> Lines: 127

> X-Priority: 3
> X-MSMail-Priority: Normal
> X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
> X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
> Message-ID: <OlaMWx9H...@TK2MSFTNGP11.phx.gbl>
> Newsgroups: microsoft.public.dotnet.languages.vb
> NNTP-Posting-Host: 213.145.180.37
> Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.phx.gbl
> Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:109297
> X-Tomcat-NG: microsoft.public.dotnet.languages.vb
0 new messages