I cannot seem to reproduce this issue within a smaller project, but I have a Top docked panel in a user control, and a panel below it containing a grid. If I set the Visible state of the Top docked panel to True in the designer then the InitializeLayout event is triggered before the columns have all been initialized. However, if this panel is set to False, then the InitializeLayout event is NOT triggered until the DisplayLayout property is first accessed within code (in my case, within the constructor, but after the default InitializeComponent call. If I change the designer to have call to PerformLayout on the panel containing the grid, before the line that seems to trigger the InitializeLayout event, then this works but is not a permanent solution.
I wish I could re-create this error, but I am hoping just looking at what triggers the InitializeLayout event would be enough to know...?
It would be good if this error could encourage a "columns changed" event? Is it worth putting in a request?
Hi,
InitializeLayout fires when the grid is bound. The BindingManager might be delaying this until the control's handle is created, so in the case where the control it not visible and nothing has asked for the DisplayLayout, it might be delayed until the control paints the first time.
In any case... if the event is firing before the columns are created, then does that mean that you are not seeing all of the columns on the screen? If you see the columns, then it probably means that InitializeLayout is firing more than once, which means you could just check for the existance of the columns you need and if they are not there, bail out. Then you can do the real initialization of the layout when the event fires again.
Another option you could explore is forcing the event to fire by making the control visible or forcing it's handle to be created. But this could be dangerous and cause other problems, so I woudn't recommend it except as a last resort.
It is only firing a single time as I already tried to check for columns before allowing my InitializeLayout code to process.
I think I'll have to move the code from Initialise layout, to the constructor - that will do the trick.
I just wanted to check whether this is a potential bug, or whether it's worth requesting an event to be fired when the columns collection changes?