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.
Unfortunately, activation email could not send to your email. Please try again.

XPMenu ComboBoxBarItem and multiple Threads

Thread ID:

Created:

Updated:

Platform:

Replies:

11109 Feb 23,2004 07:10 PM Feb 25,2004 12:49 PM Windows Forms 3
loading
Tags: Tools
Sue Harris
Asked On February 23, 2004 07:10 PM

Hi, I''m getting an exception occasionally in my overridden ComboBoxBarItem. I know why its happening (I''m calling functions in the class from a separate thread than it was created in), however the normal solution - using the ISynchronizeInvoke.InvokeRequired and ISynchronizeInvoke.Invoke doesn''t work because the ComboBoBarItem doesn''t derive from Control (which provides these). Can you please tell me how can I syncronously execute my function in the creating thread, when I''m in another thread? Thanks, Sue This is the exception I get: An unhandled exception of type ''System.ArgumentException'' occurred in system.windows.forms.dll Additional information: Controls created on one thread cannot be parented to a control on a different thread. Unhandled Exception: System.ArgumentException: Controls created on one thread cannot be parented to a control on a different thread. at System.Windows.Forms.ControlCollection.Add(Control value) at Syncfusion.Windows.Forms.Tools.XPMenus.EditableComboRenderer.CreateTextBox() at Syncfusion.Windows.Forms.Tools.XPMenus.EditableComboRenderer..ctor(IBarRenderer parent) at Syncfusion.Windows.Forms.Tools.XPMenus.BarRenderer.CreateNewRenderer(BarItem barItem) at Syncfusion.Windows.Forms.Tools.XPMenus.BarRenderer.OnBarItemsCollectionChanged() at Syncfusion.Windows.Forms.Tools.XPMenus.BarRenderer.Syncfusion.Windows.Forms.Tools.XPMenus.IBarRenderer.UpdateRenderers() at Syncfusion.Windows.Forms.Tools.XPMenus.ComboBoxItemRenderer.BarItemPropertyChanged(SyncfusionPropertyChangedEventArgs e) at Syncfusion.Windows.Forms.Tools.XPMenus.BarRenderer.BarItem_PropertyChanged(Object sender, SyncfusionPropertyChangedEventArgs e) at Syncfusion.ComponentModel.SyncfusionPropertyChangedEventHandler.Invoke(Object sender, SyncfusionPropertyChangedEventArgs e) at Syncfusion.Windows.Forms.Tools.XPMenus.BarItem.OnPropertyChanged(SyncfusionPropertyChangedEventArgs args) at Syncfusion.Windows.Forms.Tools.XPMenus.ComboBoxBarItem.set_Editable(Boolean value) at Runge.Common.UI.FieldRangeComboControl.ItemChanged() in d:\projects\xpac\xpac 8.0\runge.common.ui\fieldrangecombocontrol.cs:line 567 at Runge.Common.UI.FieldRangeComboControl.ItemChanged(Object sender, UpdateEventArgs e) in d:\projects\xpac\xpac 8.0\runge.common.ui\fieldrangecombocontrol.cs:line 555 at Runge.Common.Data.StandardItem.EndUpdate(DateTime startTime, Boolean fireOnParent) in D:\projects\XPAC\XPAC 8.0\Runge.Common.Data\StandardItem.cs:line 216 at Runge.Common.Data.StandardCollection.EndUpdate(DateTime startTime, Boolean fireOnParent) in D:\projects\XPAC\XPAC 8.0\Runge.Common.Data\StandardCollection.cs:line 519 at Runge.Common.Data.StandardItem.EndUpdate(DateTime startTime, Boolean fireOnParent) in D:\projects\XPAC\XPAC 8.0\Runge.Common.Data\StandardItem.cs:line 229 at Runge.Common.Data.StandardCollection.EndUpdate(DateTime startTime, Boolean fireOnParent) in D:\projects\XPAC\XPAC 8.0\Runge.Common.Data\StandardCollection.cs:line 526 at Runge.Common.Data.StandardItem.EndUpdate(DateTime startTime, Boolean fireOnParent) in D:\projects\XPAC\XPAC 8.0\Runge.Common.Data\StandardItem.cs:line 229 at Runge.Common.Data.StandardItem.EndUpdate() in D:\projects\XPAC\XPAC 8.0\Runge.Common.Data\StandardItem.cs:line 197

Administrator [Syncfusion]
Replied On February 24, 2004 02:46 PM

Hi Sue, Since the BarItem is not of the type ''Control'', you cannot use the ISynchronizeInvoke.Invoke method to invoke it from another thread. Instead as a workaround, you could have a custom method in the host form which returns the BarItem, and then invoke this custom method by using ISynchronizeInvoke.Invoke on the Form. Please try this and let me know how it goes. Thanks for choosing Syncfusion products. Regards, Guru Patwal Syncfusion, Inc.

Sue Harris
Replied On February 24, 2004 03:14 PM

Guru, I implemented the class as an override of the combo box bar item, because it is being used in multiple places. So requiring the parent form to have a special function is somewhat impractical. I suppose I could try using the parent controls Invoke and InvokeRequired from the ComboBoxBarItem, but what is the best way (from the ComboBoxBarItem, which is where the event occurs) for me to get the parent control? Regards, Sue

Administrator [Syncfusion]
Replied On February 25, 2004 12:49 PM

Hi Sue, Please try this approach : //Get hold of the parent form Form form = cbarItem.Manager.Form; //Let the Form implement an interface of the type : interface IMyCustomInterface { void MyCustomMethod(); } // check if the form implements this interface if(!(form is IMyCustomInterface)) { // throw an exception saying the form doesn''t // implement the necessary interface. } // You call this from within CustomComboBoxBarItem: form.Invoke("MyCustomMethod", new object[]{this}); // ''this'' is the derived ComboBoxBarItem; //Method in the Form: private void MyCustomMethod(CustomComboBoxBarItem cbaritem) { cbaritem.MyCustomComboBoxBarItemMethod(); } Please let me know if this meets your requirements. Thanks for choosing Syncfusion products. Regards, Guru Patwal Syncfusion, Inc.

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;