We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Please help me understand a Dispose issue with PopupControl

Hey guys,

I have an issue with Dispose() and popup controls that I''ve been trying to figure out but havn''t had any luck yet. Hopefully someone here can help. I''m using Syncfusion 2.1.0.9.

I have attached a small sample of a form containing two text boxes and a user control thats made up of a popup container and a popup control. This sample reproduces what I see in my real project, which is too large and complicated to include.

When I leave the user control I check to see if the data is valid in the OnEnter method of control about to be entered. If the user control''s data is not valid I want to focus back on it. Also, when I leave the user control, its popup control is disposed (as in the real app, to preserve resources). The dispose call is made in an async call using BeginInvoke. However, instead of the user control getting the focus back, Dispose calls SelectNextControl and the control after the user control will get the focus. If instead I call dispose syncronously, everything works as expected.

I''m sorry that the above explanation is confusing but if you open and run the attachment it will be much clearer.
- Run the project in the attachment
- Tab into the second control (thats the user control containing the popup)
- change its text so it doesn''t say "textBox1"
- Click the first control (the one you tabbed from)
- When this control is entered it checks the text of the user control. If it isn''t "textBox1" is sets the focus back to the user control.
- Instead of the user control getting the focus, the textbox after it gets the focus.

Comment out line 177 in MyPopupContainer and uncomment line 176 to see the correct behavior.

Please someone help me with this. I''ve been looking for the solution for a while now. I know it has something to do with async vs. sync and have a feeling that it has something to do with Dispose being called during a focus transfer. I''m not sure though if the popup controls do anything special in their Dispose calls.

I just want to understand the behavior I am seeing :)

Any help is greatly appreciated!

Thanks a lot.

-Flack

PopupTest.zip

4 Replies

AR Anupama Roy Syncfusion Team September 12, 2006 07:16 AM UTC

Hi Flack,

Giving an InvokeRequired condition before passing the function DisposePopupCalendar to BeginInvoke will resolve this problem.

Please take a look at the code snippet below:

protected virtual void SetEditMode(bool on_)
{
try
{
if (on_)
{
MakeSurePopupCreated();
}
else if (_calendarPopUp != null)
{
//Using DisposePopupCalendar() directly is ok but using BeginInvoke causes the issue
//DisposePopupCalendar();
if(this.InvokeRequired )
{
BeginInvoke(new MethodInvoker(DisposePopupCalendar));
}
}
_editMode = on_;
}
catch (Exception ex_)
{
MessageBox.Show(ex_.ToString());
}
}


Thanks for your interest in Syncfusion products.

Regards,

Anu.


AD Administrator Syncfusion Team September 12, 2006 01:27 PM UTC

Great. Thanks for the help.

Do you happen to know why I was seeing the focus not go to the user control but go the the next control instead when just using BeginInvoke and why calling it in a syncronous manner or checking if InvokeRequired fixes it?

-Flack


AD Administrator Syncfusion Team September 12, 2006 01:33 PM UTC

Also, using InvokeRequired will cause the DisposePopupCalendar to not be called at all.

How about if I always want it to be Disposed? Is there a way to do it asyncronously and still have the focus correctly set to the user control when setting it from the OnEnter method of another control?

-Flack


AR Anupama Roy Syncfusion Team September 13, 2006 02:02 PM UTC

Hi Flack,

I could see that the method is not getting called when InvokeRequired is used.However,I could not figure out the exact issue behind this.I will investigate deeper and let you know if I can find out something.

Thanks,

Anu.


Loader.
Live Chat Icon For mobile
Up arrow icon