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

Loading DataBoundGrid style from a save configuration

Hi, I'm trying to reload style options for a DataBoundGrid, from a previously saved parameter list. Reading and writing the parameters is no problem. What is giving me fits though is determining when the grid has completed initialization, so I can update the settings. This is done as part of a grid restore operation, when the app is started. Currently I'm trying to do it from an Init() sub, that is run after InitializeComponent() (the Windows Form Designer generated code) has completed. When I go to update the DataBoundColumns, both g.GridBoundColumns.count and g.Binder.InternalColumns.count, are set to 0. This of course generates errors if I try to update the columns. Subsequent checks (after the load) shows columns in g.Binder.InternalColumns. Can you tell me when DataBoundGrid initialization has completed and what event(s) I can use as an indication it is safe to update? FYI, the DataBoundGrid is contained in your DockingManager component. Thanks, Doug

3 Replies

AD Administrator Syncfusion Team September 24, 2003 01:53 PM

There is no such init event because the grid itsself only can reacts to actions that happen in your parent forms code. The reason that the InternalColumns collection is empty at that point is that probably the binding context has not been specified. The BindingContext of a control is only available once all controls have been properly parented to their respective parent controls. So, if you have the grid inside a panel and that panel will later be added to a form. The grids binding context is set when the panel is added to the form. At that time the grids gets a BindingContextChanged notification and will call InitializeColumns if they have not yet been initialized. If on the other side the grid is already added to a form and therefore the binding context initialized then the grid will initialize columns as soon as you initialize its DataSource property. Hope this is not explained too complicate. So, some events you might look for are BindingContextChanged and DataSourceChanged. Best is of course if the parent form could fire a quick method call to your grid once it is done loading, e.g. from Form_Load. Stefan


DL Doug Lind September 25, 2003 07:24 AM

Thanks for the explanation. I'll give the form load event a try. I avoided that initially because the description indicated that it was called "when" the the form was loaded and it seemed that what was need was "after". The other two events you mentioned may also be a good bet. If nothing else I figured I could set up a timer upon loading the form to watch for grid initialization to complete, then dispose of the timer and perform the update. Kinda klunky but it should work. Again, thanks Doug > > There is no such init event because the grid itsself only can reacts to actions that happen in your parent forms code. > > The reason that the InternalColumns collection is empty at that point is that probably the binding context has not been specified. The BindingContext of a control is only available once all controls have been properly parented to their respective parent controls. > > So, if you have the grid inside a panel and that panel will later be added to a form. The grids binding context is set when the panel is added to the form. At that time the grids gets a BindingContextChanged notification and will call InitializeColumns if they have not yet been initialized. > > If on the other side the grid is already added to a form and therefore the binding context initialized then the grid will initialize columns as soon as you initialize its DataSource property. > > Hope this is not explained too complicate. > > So, some events you might look for are BindingContextChanged and DataSourceChanged. > > Best is of course if the parent form could fire a quick method call to your grid once it is done loading, e.g. from Form_Load. > > Stefan >


DL Doug Lind September 25, 2003 07:31 AM

Stefan, FYI: The form load event did the job.

Loader.
Live Chat Icon For mobile
Up arrow icon