Hi all!
I wrote a usercontrol that contains a Tabcontrol. I need to dynamically add tabs and nested grids in the according tabpagecontrols. I managed to do that, but i have the problem to retrieve or alter the displaylayout settings after the datasource was assigned to the grid. If I do not try to manke changes to the displaylayout in the usercontrol and the control is shown on the form it works fine, but i need to change displaylayout settings. Where is the error in code, means, when can i set the displaylayout setting?
--code:
//Getting Data for tabs
DST = Connect.GetDataSet(strSQLQuery);
//clearing all tabs
this.ultraTabControl1.Tabs.Clear();
GridsToFormat = new Infragistics.Win.UltraWinGrid.UltraGrid[DST.Tables[0].Rows.Count];
int i = 0;
//Create Tab for each row
foreach (System.Data.DataRow Rwo in DST.Tables[0].Rows)
{
Infragistics.Win.UltraWinTabControl.UltraTab Tab = new Infragistics.Win.UltraWinTabControl.UltraTab();
Infragistics.Win.UltraWinGrid.UltraGrid StockGrid = new Infragistics.Win.UltraWinGrid.UltraGrid();
Infragistics.Win.UltraWinTabControl.UltraTabPageControl TabPageControl = new Infragistics.Win.UltraWinTabControl.UltraTabPageControl();
((System.ComponentModel.ISupportInitialize)(StockGrid)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.ultraTabControl1)).BeginInit();
this.ultraTabControl1.SuspendLayout();
TabPageControl.SuspendLayout();
this.SuspendLayout();
this.ultraTabControl1.Controls.Add(TabPageControl);
Tab.TabPage = TabPageControl;
Tab.Key = System.Convert.ToString(Rwo["MST_Bezeichnung"]);
Tab.Text = System.Convert.ToString(Rwo["MST_Bezeichnung"]);
this.ultraTabControl1.Tabs.Add(Tab);
TabPageControl.Controls.Add(StockGrid);
this.intMedikament_ID = System.Convert.ToInt32(Rwo["LAG_Medicament_ID"]);
TabPageControl.Controls.Add(this.grdDosageHistory);
TabPageControl.Location = new System.Drawing.Point(1, 23);
TabPageControl.Name = "ultraTabPageControl1";
TabPageControl.Size = new System.Drawing.Size(389, 327);
TabPageControl.Controls[0].Dock = DockStyle.Fill;
((System.ComponentModel.ISupportInitialize)(StockGrid)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.ultraTabControl1)).EndInit();
this.ultraTabControl1.ResumeLayout(false);
TabPageControl.ResumeLayout(false);
this.ResumeLayout(false);
//Fetching Dataset for Grid and assign datasource
FillValues(StockGrid);
//Formatting the grid - here the error occurs (Displaylayout is null)
FormatGrid(StockGrid);
if (Convert.ToInt32(Rwo["LAG_Medicament_ID"]) == this.intActiveMedikamentID)
this._ActiveStockGrid = StockGrid;
}
GridsToFormat[i] = StockGrid;
i++;
Please suggest, what i can do... Leaving out the funtion (FormatGrid(...) works, but displaylayout looks ugly...
Thank, Marc!
It's pretty hard to read this code, and I'm not sure exactly what problem you are having. What exactly is not working here?
The best way to modify the layout of the grid is to use the InitializeLayout event.
If you need to apply appearances or calculations to individual rows, then you should use the InitializeRow event instead of looping through all of the rows.
usually, when I assigne the datasource to a grid , i can imediately change the displaylayout like header.caption ord hide columns and so on.
I the code i like to add tabs to a tabcontrol based on database values. For each row a new tab should be generated, that contains a grid with special data according to the Tab. Therefor I supsend the layout to add a tab and the gridcontrol to the tabpage and after that i resume the layout. But after resuming layout i do not have a displaylayout yet, although i already assigned the datasource to the grid, that means i raise an errormessage, when trying to set displaylayouts header.caption for example.
If iI do not try to change the display layout and the usercontrol is shown, it shows the grids with the correct content, but the displaylayout is not as i wish it to be. what is missing, so that i can change the grids displaylayout when adding tabscontrols dynamically?