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?
Mike,
I am trying to export grid in PDF but the column content is not displaying correctly it's cutting a little bit.
Please see my code and attached screenshot.
Private Sub ugrdExporter_ExportStarted(sender As Object, e As Infragistics.Win.UltraWinGrid.DocumentExport.ExportStartedEventArgs) Handles ugrdExporter.ExportStarted
Try
ugrdExporter.AutoSize = Infragistics.Win.UltraWinGrid.DocumentExport.AutoSize.SizeColumnsToContent
Catch ex As Exception
End Try
End Sub
Private Sub ugrdExporter_InitializeRow(sender As Object, e As Infragistics.Win.UltraWinGrid.DocumentExport.DocumentExportInitializeRowEventArgs) Handles ugrdExporter.InitializeRow
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.
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
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.
I am using 13.1.20131.2060 version.
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 ?