Hi,
I have a UltraGrid control in which, I am trying to do a few things as mentioned below...
I have an ultraGrid and ultraDataSource which are initialized and assigned to in the InitializeComponent() method of the parent. I have created individual dictionaries for UltraDataColumn and UltraGridColumn respectively.
- Firstly, I populate the Columns names array
- Secondly, I populate the data which is an array of class objects.
- Then I create a UltraDataColumn dictionary from the Columns array; but do not yet add it to UltraDatasource
- Next I create another dictionary of corresponding UltraGridColumns from the dictionary of UltraDataColumns, but do not yet add it to UltraGrid
- Since, now the column collections are ready and since the UltraDataSource is already bound to UltraGrid, the Grid Columns collection already has the column information
- Now, add the UltraGridColumns to UltraGrid and then add the UltraDataColumns to UltraDataSource.
- In Initialize_Layout event handler, I initialize layout, band and provide values to overrides and also format headers looping through the UltraGrid's column collection
- In the Initialize_Layout, I am trying to set the 0th column that serves as row header as a Fixed Column, which is always visible and remains in position on scrolling. I have set Fixed property to true, FixedColumnIndicators to None yet the column does not fix itself. I have tried this setting in RowLayoutMode as GroupLayout as well as COlumnLayout respectively. But it still fails....
- I am able to set the appearance for the headers in Initialize_Layout. Everything, except BackColor is rendered properly. I have tried to find out as to what is causing the problem;
- I have multiple Ultra tabs on the UI and each tab has an UltraGrid. I am doing custom drawing of +/- signs in column headers to implement expandable Columns. I have assigned a creation filter to the grid. With some deal of research, I am able to provide +/- buttons in headerUI. However, the UltraGrid custom drawing is lost when the tab is changed and the same ultra Grid is shown again and it does show the grid without any formatting...
- Is there a way to fire InitializeLayout on purpose?
Please advice if I am doing anything wrong...
Thanks,
Bhushan.
Hi Bhushan,
Thank you for posting in our forums.
For the fixed headers, if they aren’t working, you probably need to set the UseFixedHeaders property of the DisplayLayout to true:
this.ultraGrid1.DisplayLayout.UseFixedHeader = true;
For the Header color it is probably overridden by the style that the header uses. In order to override this use the following line:
this.ultraGrid1.DisplayLayout.Override.HeaderStyle = HeaderStyle.Standard;
As for the CreationFilter, there really isn’t a way for me to know what is going on, unless I see your application. Most probably there is some issue in your CreationFilter, but without seeing it there is now way to know exactly what.
What do you mean by “Is there a way to fire InitializeLayout on purpose”? The event is fired when the grid is provided with a data source. If you want to call the code inside it multiple time, encapsulate the code inside the event in a method and then call the method.
Please let me know if you have any additional questions.
As of now, I do have a lot of questions, but for now got to get a few implementations working....
The InitializeLayout isn’t called on the Show method. In fact it is impossible to be called there, since the Show method is part of the Control class created by Microsoft and InitializeLayout event is defined on the UltraGrid class by us. In order to raise the event in the Show method we will need to override the Control method and this simply isn’t the case. It is called when the data source is provided or changed. You can see this forum thread for more information on this.
Anyway, it seems that there is something in your custom implementation that is causing the issues in your case. In order to assist you further on all this I would need a small sample that demonstrates this issue. Once I have the sample I will be glad to assist you further on this.
First of all many thanks to your explanations so far and suggestions; owing to them made me revisit the code and now I have resolved the issue. There are 2 cases here...
[1] When the datasource is assigned in the designer by default, the grid and the datasource are empty i.e., without any schema as wellas data. In this case, as per my observation, the firing of the InitializeLayout is delayed till the point where Grid is shown. If there is no specific call to grid.show, then grid is is displayed by default on Form load event and is displayed once the method executes. Also, if there is a specific need to call the grid.show method as in the case of MVC implementation, the grid.Show becomes responsible for the showing of the grid and that is when the InitializeLayout is invoked.
[2] On the other hand, if we delay the datasource assignment and move it out of InitializeComponent() method of the designer, then as you have mentioned, the InitializeLayout event is fired when the datasource is assigned to the grid. And this is what I have done. I have kept the grids hidden in the designer's InitializeComponent() method and then in my custom method to show the grid, I have done the following...
private void ShowInfragisticsGrid()
{
UltraGrid grid = null;
UltraDataSource ds = null;
switch(ultraTab.SelectedTab.Name)
case "tab1":
grid = gridOnTab1;
ds = dsForTab1;
break;
case "tab2":
grid = gridOnTab2;
ds = dsForTab2;
case "tab3":
grid = gridOnTab3;
ds = dsForTab3;
default:
}
grid.DataSource = null;
m_HeaderArray = FetchColumnHeadersData(ultraTab.SelectedTab.Name);
m_DataArray = PopulateDataStructure(ultraTab.SelectedTab.Name);
PrepareUltraDataSourceColumns(ds);
PrepareUltraGridColumns(grid);
PopulateUltraDataSourceRows(ds);
grid.Datasource = ds;
//grid.Update();
//grid.Invalidate();
//grid.Refresh();
grid.Visible = true;
I call this on the Tab Control's Tab Changed event and now it works fine. Assigning grid.Datasource to null before the processing and then reassigning the datasource back to the grid, makes the call to InitializeLayout and the logic for Creation Filters is thus invoked now.
[3] While looking through the code and working along, I have few more doubts in my mind over the calls to grid.Update(), grid.Invalidate(), grid.Refresh() and likewise. What is the difference between all these calls? I have read the documentation, however, I am not able to visualize the exact scenario where in each of these method calls serves a purpose. So if you could let me know as to when these calls be useful?
[4] Also, I have some confusion over the use of grid.Show() / grid.Hide() versus grid.Visible = true / grid.Visible = false. What is the difference between the two cases and what scenarios which one to use?
I am glad that your CreationFilter is working properly now.
As for the difference between the Update, Invalidate and Refresh methods: The Invalidate method invalidates the whole control, making sure that it will be redrawn on the next paint message. The Update method forces a synchronous redraw of the control’s invalidated areas. The Refresh method invalidates the control and forces redrawing of the control. It is equal to first calling the Invalidate method and then calling the Update method immediately after that.
There is no difference between grid.Show()/grid.Hide() and grid.Visible = true/grid.Visible = false. In fact what the methods do is that they set the Visible property to true or false.