Master Detail Grids setup at runtime

Posts   
 
    
tdoll
User
Posts: 6
Joined: 15-May-2007
# Posted on: 19-May-2007 11:52:22   

Hello,

in my form i have two datagridviews (one for the masterentitycollection) and one for the clientcollection(s).

The databinding of the mastergrid at runtime (over a combobox, which includes all found entitycollections (per reflection) functions well.

in an second combobox i show all found relations for the masterentitycollection and now want to setup the databinding from the detailgrid over this combobox (per selectedIndex changed event)

Each Grid is databound to an own bindingsource. To setup the grids datasource i change the datasource/datamember of the bound bindingsource.

How can i achieve this?

In Desingermode this functions quite well, but it have to setup the master/detailgrids at runtime.

I have tried over IBindinglist, but when i want to setup the datamember property i get the error "Collections derived from this class aren't thread safe by default. Use your own locking system in your code."

kind regards Tom

Posts: 254
Joined: 16-Nov-2006
# Posted on: 19-May-2007 23:10:34   

Can you post a call stack when the exception is raised please?

tdoll
User
Posts: 6
Joined: 15-May-2007
# Posted on: 26-May-2007 08:12:14   

MattAdamson wrote:

Can you post a call stack when the exception is raised please?

ok, here it is...

System.NotSupportedException wurde nicht behandelt. Message="Collections derived from this class aren't thread safe by default. Use your own locking system in your code." Source="SD.LLBLGen.Pro.ORMSupportClasses.NET20" StackTrace: bei SD.LLBLGen.Pro.ORMSupportClasses.CollectionCore`1.System.Collections.ICollection.get_SyncRoot() bei System.Windows.Forms.BindingSource.get_SyncRoot() bei DevExpress.Data.DataControllerBase.CreateHelper() bei DevExpress.Data.DataControllerBase.OnListSourceChanged() bei DevExpress.Data.DataControllerBase.SetListSourceCore(IList value) bei DevExpress.Data.DataControllerBase.OnBindingListChanged(ListChangedEventArgs e) bei DevExpress.Data.DataController.OnBindingListChanged(ListChangedEventArgs e) bei DevExpress.Data.CurrencyDataController.RaiseOnBindingListChanged(ListChangedEventArgs e) bei DevExpress.Data.Helpers.ListDataControllerHelper.OnBindingListChanged(Object sender, ListChangedEventArgs e) bei System.ComponentModel.ListChangedEventHandler.Invoke(Object sender, ListChangedEventArgs e) bei System.Windows.Forms.BindingSource.OnListChanged(ListChangedEventArgs e) bei System.Windows.Forms.BindingSource.SetList(IList list, Boolean metaDataChanged, Boolean applySortAndFilter) bei System.Windows.Forms.BindingSource.ResetList() bei System.Windows.Forms.BindingSource.set_DataMember(String value) bei GUI.MainForm.cbDetail_SelectedIndexChanged(Object sender, EventArgs e) in C:\Entwicklung\LLBLGenPro\C2C_CALC_DAL\GUI\MainForm.vb:Zeile 209. bei DevExpress.XtraEditors.Repository.RepositoryItemComboBox.RaiseSelectedIndexChanged(EventArgs e) bei DevExpress.XtraEditors.ComboBoxEdit.UpdatePopupEditValueIndex(Int32 prevIndex) bei DevExpress.XtraEditors.ComboBoxEdit.set_EditValue(Object value) bei DevExpress.XtraEditors.PopupBaseEdit.AcceptPopupValue(Object val) bei DevExpress.XtraEditors.PopupBaseEdit.DoClosePopup(PopupCloseMode closeMode) bei DevExpress.XtraEditors.PopupBaseEdit.ClosePopup(PopupCloseMode closeMode) bei DevExpress.XtraEditors.PopupBaseEdit.ClosePopup() bei DevExpress.XtraEditors.Popup.PopupListBox.OnMouseUp(MouseEventArgs e) bei System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) bei System.Windows.Forms.Control.WndProc(Message& m) bei DevExpress.Utils.Controls.ControlBase.WndProc(Message& m) bei System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) bei System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) bei System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) bei System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) bei System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods. IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData) bei System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) bei System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) bei System.Windows.Forms.Application.Run(Form mainForm) bei GUI.MainForm.Main() in C:\Entwicklung\LLBLGenPro\C2C_CALC_DAL\GUI\MainForm.Designer.vb:Zeile 2. bei System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args) bei System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) bei Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() bei System.Threading.ThreadHelper.ThreadStart_Context(Object state) bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) bei System.Threading.ThreadHelper.ThreadStart()

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39914
Joined: 17-Aug-2003
# Posted on: 26-May-2007 11:22:30   

You use multi-threading and I then think the devexpress code calls SyncRoot on the collection. This gives the exception as SyncRoot throws the exception because a collection's SyncRoot shouldn't be read, as the collection isn't thread safe. This means that if something would be returned by SyncRoot() the assumption would be made that what was returned would be thread safe which it isn't.

Why do you use multi-threading in this case?

Frans Bouma | Lead developer LLBLGen Pro
tdoll
User
Posts: 6
Joined: 15-May-2007
# Posted on: 06-Jun-2007 16:46:39   

Otis wrote:

You use multi-threading and I then think the devexpress code calls SyncRoot on the collection. This gives the exception as SyncRoot throws the exception because a collection's SyncRoot shouldn't be read, as the collection isn't thread safe. This means that if something would be returned by SyncRoot() the assumption would be made that what was returned would be thread safe which it isn't.

Why do you use multi-threading in this case?

Hmmm... good question.

I have only setup a default project with DevExpress-grids. I have not setup multi-treading in Visual Studio and think for this application i don't need it. But where can i deactivate it?

The primary question is for me how to achieve the function of runtime defined master/detail grids which can be setup with an formeditor (i.e. how to get the related entitycollections from an entitycollection and setup the master/detail context with the masterbindingsource and the related detailbindingsource) The configuration of the form (controls and properties, databinding,...) is saved in an XML-file and restored/setup when the form load event is active. So all desing and databinding has to be done dynamically at runtime.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 06-Jun-2007 17:02:34   

Are you looking for a way to get related entityCollections knowing the corresponding entityRelations? I'm not sure, but I think the following thread is somehow related to what you need: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=8749