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?
DannyvdK said: 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.
The InitializeLayout event will fire after step 1 here, setting the DataSource of the grid. But it will not fire after step 4, or any of the other steps you listed here. If it's firing again, then something else is going on.
Anyway, in your initial post you said that the grid has no child rows at first. So there's nothing to size in the second band. Did I misunderstand?
DannyvdK said: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.
Yes, AllowColSizing is the correct property. Sorry for the confusion. :)
DannyvdK said:3) Is it perhaps a problem that the Employees band uses Row Layout for the column arrangement and Tasks band uses Groups and Levels?
Employees is the second band? I guess that might be related, but the PerformAutoResize method should still work, assuming you call that method after the data in the Employees band has been added to the grid.
Perhaps you could post a small sample project demonstrating the behavior you are getting? If I could see a sample, I could debug it and tell you exactly why it's not working.
Hey Mike,
Sorry, busy busy busy...
Finally got around to making a small sample project (see attached ZIP file)
1) start up project.
- Notice that the info in both grids are sized properly
- As an extra problem, also notice that a + sign is displayed in front of the employees in the right grid while not actually having tasks in the collection. But this is a different problem. I worked around this in the real application by expanding and collasping all.
2) Select 'Task 1 blablabla..." in the left grid. Select an employee (for example "Peter") in the right grid.
3) Click on "Add Task"
- Notice how the added task is not resized at all.
Why?
On one of post it mentined like this :The best thing to do is to leave on the AutoSize property or auto-size the columns in the export layout to ensure that the data will fit in the report.
So how to do autosize column ? is it same like this ?
ugrdExporter.AutoSize = Infragistics.Win.UltraWinGrid.DocumentExport.AutoSize.SizeColumnsToContent
I am using 13.1.20131.2060 version.
Hi,
I'm not sure if BeginExport is any better. That event is obsolete, so you might try ExportStarting, but event that might be too late. The best thing to do is to set the property before you call the Export method. I typically set it at design-time.
If that still doesn't work, then my best guess is that there is something about your data or your grid settings which is causing the autosizing to fail. What version of the controls are you using?
If you can post a small sample project demonstrating the problem, we would be happy to check it out.
Thanks for quick reply, So now I am doing like this still it's not working.
Private Sub ugrdExporter_BeginExport(sender As Object, e As Infragistics.Win.UltraWinGrid.DocumentExport.BeginExportEventArgs) Handles ugrdExporter.BeginExport
ugrdExporter.AutoSize = Infragistics.Win.UltraWinGrid.DocumentExport.AutoSize.SizeColumnsAndRowsToContent
End Sub
The AutoSize property on the exporter needs to be set before the export operation begins. You can't set it in these events - it's too late by then.