Hello,
we're using UltraGrid 10.1. Is there a way to force the grid to fully initialize before it's displayed on a form?
What I mean specifically is I need to get column's width by accessing DisplayLayout.Bands[0].Columns[i] after the following code is executed:
var grid = new UltraGrid();grid.DataSource = new List<string> {"item1", "item2"};
However there are no columns in the columns collection until the grid is displayed. InitializeLayout event is not raised until the grid is displayed as well.
How can I force the grid to fully initialize itself right after it's created and DataSource is set?
Thanks,Vitaly
Hi Vitaly,
Try calling grid.Update before you try to get the columns.
If that doesn't work, then another option would be to use the grid's InitializeLayout event to get what you need. The columns should exist by the time that event fires.
Hi Mike,
Sorry for the delayed response.
grid.Update doesn't do the trick - the data is still not fully loaded. Waiting for InitalizeLayout doesn't really work as well and here is why. We have a grid ('main grid') with a dropdown in a cell. The dropdown button hosts another one-column grid ('dropdown grid'). What should happen is the width of the column of the main grid should be set to the width of the dropdown grid. And the problem is that the columns of the dropdown grid are not 'initialized' until the dropdown grid is shown, which happens when the user clicks the dropdown button (it's now when InitializeLayout is raised). And thus it's unknown what the dropdown grid width is going to be when main grid's column width should be set.
Do you have any ideas on how to resolve?
Thanks!
Hi,
Okay, that makes sense. So what I would do is use the InitializeLayout event of the main grid. Inside this event, the dropdown grid doesn't have any columns because it has never painted and probably doesn't have a BindingContext since it has never been dropped down.
So what you can do is set it's BindingContext to the form's BindingContext and then call Update on this dropdown grid to force it to paint. You may also need to make sure it's Visible property is true before calling Update.
That should force the columns in the dropdown grid to be created and then you can get the width of the column you need.