I have a Hierarchical Datagrid from version 12.1.
I load a collection of class Employee in de Datasource. Each Employee has a property Tasks which is a collection of class Task.The property Tasks however is always initially empty (so the grid is 1 level deep).
In my app the enduser can assign a Task to an Employee. The Task row needs to be shown beneath the Employee row, this all works fine. But I also need to autosize all the columns of all the rows. And I want to size everything so that all the data in the cells are visible to the enduser.
I try to do this in the InitializeLayout eventhandler, as follows:
private void ultraGrid_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e) { Infragistics.Win.UltraWinGrid.UltraGrid grid = (Infragistics.Win.UltraWinGrid.UltraGrid)sender; grid.DisplayLayout.Override.AllowUpdate = Infragistics.Win.DefaultableBoolean.False; grid.DisplayLayout.Override.CellClickAction = Infragistics.Win.UltraWinGrid.CellClickAction.RowSelect; grid.DisplayLayout.Override.SelectTypeRow = Infragistics.Win.UltraWinGrid.SelectType.Single; Infragistics.Win.UltraWinGrid.UltraGridLayout layout = e.Layout; Infragistics.Win.UltraWinGrid.UltraGridOverride ov = layout.Override; ov.AllowColSizing = Infragistics.Win.UltraWinGrid.AllowColSizing.Free; layout.Bands[0].Override.RowSpacingAfter = 2; layout.Bands[0].Override.RowSpacingBefore = 3; foreach (var band in layout.Bands) { band.PerformAutoResizeColumns(false, Infragistics.Win.UltraWinGrid.PerformAutoSizeType.AllRowsInBand); foreach (var col in band.Columns) { col.PerformAutoResize(Infragistics.Win.UltraWinGrid.PerformAutoSizeType.AllRowsInBand, true); } } }
The PerformAutoResize in the foreach loop is not giving me the result I expected. The added Tasks at level 2 in the grid are not resized at all so it seems. Can you please help me Infragistics? I need your expert advice on this one.
Hi
PerformAutoResize is a method that resizes the columns at the time you call it. The columns are not continuously resized all the time. So if you add a new row to the grid, you need to call PerformAutoResize again on the columns of that band in order to make it resize.
Also, the columns in each band of the grid are synchronized by default. So column 0 in band 0 will always have the same width as column 0 in band 1. You probably want to turn this off so you can size the columns in each band independently. You do that by setting the ColSizing property on the Override to one of the 'Free' settings.
Hi Mike,
First off, thanks for answering.
1) What I do after a task is added to an Employee is:
1: this.ultraGrid1.DataSource = Employees; 2: this.ultraGrid1.Rows.Refresh(Infragistics.Win.UltraWinGrid.RefreshRow.ReloadData, true); 3: this.ultraGrid1.Rows.ExpandAll(true); 4: this.ultraGrid1.ActiveRow = this.ultraGridPrescribed.Rows.First();
InitializeLayout eventhandler is called after codeline 1 and 4. There (in the InitializeLayout event handler) I go in the foreach loop through each band and column to call PerformAutoResize like you can see in the code sample from my 1st post. So... What am I doing wrong according to you? I don't understand.
2) I couldn't find the ColSizing property, but I did find the AllowColSizing property in the Override property of the Band. So I set AllowColSizing property to Free on the bands Employees and Tasks. And I also set ColumnAutoSizeMode to AllRowsInBand at both bands. Didn't work.
3) Is it perhaps a problem that the Employees band uses Row Layout for the column arrangement and Tasks band uses Groups and Levels?