c# Event problem (Let me know this is event problem or not..)

  • Thread starter Thread starter cty0000
  • Start date Start date
C

cty0000

Please anybody help me...

I have some serious problem..
I'm doing to keep equpiment list(string)..
In my code, there are 3 page which are having 4 equpiment ID (user
control.)


like this window FORM


==================================================================
=
= ============= ============= ============= =============
= = equpment ID = = equpment ID = = equpment ID = =
equpment ID =
= = combo box = = combo box = = combo box = =
combo box =
= = (user object) = = (user object) = = (user object)
= = (user object) =
= ============= ============= ============= =============
=
=
=
= PAGE 1 BUTTON PAGE 2 BUTTON PAGE 3 BUTTON
====================================================================


every userobject can select equpiment (1000,2000,3000 or 4000)
every page has 4 equpment list, so totally 12 equpment can be display
at once..


1. when combo box click(means equipment change), event is occured
2. FORM window catch event and keep equipment inforamtion at
dictionary<int, list<String>>
(int is page number, string is equipment ID)
3. if page changed, display thier (page) own equipment list


The problem is ... event...


I select 1000, 2000 ," ", " " at page 1
and change page to 2 (all user control clear because page 2 is not
select any equipment)
I select " ", 3000,4000, " " at page 2
I return select page 1


I expected 1000, 2000, " " ," " but.. result is 1000,2000,4000, " "


I do not know whay 4000 is displayed...


So i debug code...
the event was problem
I code like following...


private void comboBox1_SelectedIndexChanged_1(object sender,
EventArgs
e)
{
equipmentID = comboBox1.Text;
equipmentChanged(new object(), new EventArgs());
//equipmentChanged(this, new EventArgs());
}


equipmentChanged is event...

If I comment out equipmentChanged event and calll event by other, the
problem is not happened...
(example I made a button on usercontrol and send event by button
click)


I want to attach the sample code but I don't know how to attach at
this usernet group..
So please down load my c# sample code and please teach me what is
problem...

http://download.yousendit.com/B1F068D56D804070
there is testWindow.zip file at that site..

I tooks 1 day to resolve this problem but I still could not found
reason..


Please.. please.. please...
 
[...]
http://download.yousendit.com/B1F068D56D804070
there is testWindow.zip file at that site..

I tooks 1 day to resolve this problem but I still could not found
reason..

Nor is it clear that you've resolved the issue in a satisfactory manner.

In any case, the problem happens because when you change the value of a
ComboBox, that can cause the SelectedIndexChanged event to be signaled.
In your code, when the SelectedIndexChanged event is signaled, you copy
_all_ of the current values of the ComboBox instances (via your user
control) to the current page's list of values. Of course, since you've
already changed the current page number by that point, you wind up taking
the current value of each of the ComboBox instances beyond what you've
already updated and copying those into your current page.

This is easily seen in the debugger by noting that your userControlList
for the given page does match what each ComboBox is showing you. So then
you set a breakpoint where you change the userControlList for the given
page and note that when you switch back to page 1, you actually wind up in
the EquipmentChanged() method copying values from each user control into
your current page's userControlList. This is the point at which the value
from the ComboBox on the previous page is copied to the userControlList
for the current page. And of course, moments later, you then take that
changed value to update the ComboBox again.

I think you would be well-served by practicing this scenario and others in
the debugger, so that you are better at using the debugger. IMHO, simply
putting appropriate breakpoints in the debugger and watching what happens
to your data makes it very clear what's wrong with your code.

How to fix it is another matter, but I would say as a start it is not a
good idea to copy _all_ of your values when just _one_ has changed. You
have a variety of other things that I would fix in your code, but it's
that one behavior that's causing the specific problem you're asking about.

Pete
 
Please anybody help me...

And for the record...

I replied to your post _in spite of_ the number of times you posted it,
rather than _because of_ the number of times you posted it. My usual
reaction to seeing that number of repeats is to just ignore the post
altogether.
 
[...]
http://download.yousendit.com/B1F068D56D804070
there is testWindow.zip file at that site..
I tooks 1 day to resolve this problem but I still could not found
reason..

Nor is it clear that you've resolved the issue in a satisfactory manner.

In any case, the problem happens because when you change the value of a
ComboBox, that can cause the SelectedIndexChanged event to be signaled.
In your code, when the SelectedIndexChanged event is signaled, you copy
_all_ of the current values of the ComboBox instances (via your user
control) to the current page's list of values. Of course, since you've
already changed the current page number by that point, you wind up taking
the current value of each of the ComboBox instances beyond what you've
already updated and copying those into your current page.

This is easily seen in the debugger by noting that your userControlList
for the given page does match what each ComboBox is showing you. So then
you set a breakpoint where you change the userControlList for the given
page and note that when you switch back to page 1, you actually wind up in
the EquipmentChanged() method copying values from each user control into
your current page's userControlList. This is the point at which the value
from the ComboBox on the previous page is copied to the userControlList
for the current page. And of course, moments later, you then take that
changed value to update the ComboBox again.

I think you would be well-served by practicing this scenario and others in
the debugger, so that you are better at using the debugger. IMHO, simply
putting appropriate breakpoints in the debugger and watching what happens
to your data makes it very clear what's wrong with your code.

How to fix it is another matter, but I would say as a start it is not a
good idea to copy _all_ of your values when just _one_ has changed. You
have a variety of other things that I would fix in your code, but it's
that one behavior that's causing the specific problem you're asking about.

Pete

I have finally found out the problem and fix it by your teaching
Thanks thanks thankssssssss alot...
 
Back
Top