I've got an UltraWinGrid (v12.1) that contains an unbound column that calculates a running total.
As soon as I've set my DataSource, I call PerformAutoResizeColumns so that the layout "fits" nicely.
This works beautifully for bound columns, but not my unbound column.
If I put a button on my form and click it once the data has loaded, PerformAutoResizeColumns works nicely for the unbound column.
Out of the myriad of events that I can hook up to, which should I be using to get this working properly please??
Cheers,
James
Mike... you're a star!!!
That's hit the nail right on the head.
It works perfectly for me as I'm dealing with a small number of records in my view.
Many thanks,
Hi James,
Okay, I tried it out and it seems like the issue is that the calculations are performed asynchronously. So at the time you are performing the resize, the column has not been calculated, so it's being resized based on it's current text, which is empty.
The only way to get around that would be to force the calculations to be performed before the resizing. This might not be very performant, depending on the number and complexity of your calculations, but that's really the only way. I got it to work like so:
this.ultraGrid1.SetDataBinding(this.ultraDataSource1, "Band 0");this.ForceAllCalculations();this.ultraGrid1.DisplayLayout.PerformAutoResizeColumns(false, PerformAutoSizeType.AllRowsInBand, AutoResizeColumnWidthOptions.All);
private void ForceAllCalculations() { this.ultraCalcManager1.CalcFrequency = Infragistics.Win.UltraWinCalcManager.CalcFrequency.Manual; this.ultraCalcManager1.DeferredCalculationsEnabled = false; try { this.ultraCalcManager1.ReCalc(); } finally { this.ultraCalcManager1.DeferredCalculationsEnabled = true; this.ultraCalcManager1.CalcFrequency = Infragistics.Win.UltraWinCalcManager.CalcFrequency.Asynchronous; } }
Hi Mike,
Thanks for the suggestion... here's some feedback:
I've managed to get this working in an extremely kludgy fashion.
private void NominalLedgerComboEditor_ValueChanged(object sender, EventArgs e) { var nominal = (int)NominalLedgerComboEditor.Value; postingGrid.Paint += new PaintEventHandler(postingGrid_Paint); postingBindingSource.DataSource = _agreement.AllPostings.Where(p => p.Nominal == nominal).OrderBy(p => p.ValueDate).ThenBy(p => p.Id).ToList();}
void postingGrid_Paint(object sender, PaintEventArgs e) { postingGrid.Paint -= new PaintEventHandler(postingGrid_Paint); new System.Threading.Timer(AutoFormatGridCallback, postingGrid, 10, -1); }
void AutoFormatGridCallback(object grid) { ((UltraGrid)grid).DisplayLayout.Bands[0].PerformAutoResizeColumns(false, PerformAutoSizeType.AllRowsInBand, AutoResizeColumnWidthOptions.All); }
So here's what I'm doing:
This works, but it isn't pretty!!!
Any thoughts??
Try this... immediately before you call PerformAutoResizeColumns, call grid.Update. That should force the grid to paint once before the autosize occurs.
If that does not work, then try moving this code into the grid's Paint event. You can use a flag so that it's only executed the first time the event fires (since autosizing every time the grid paints would be very inefficient).
Thanks for the swift response.
Info about the column:
The band is being resized with the following call:
The grid is called postingGrid which has a data source of postingBindingSource.
I set the DataSource on the bindingSource and then make the call to format the grid:
postingBindingSource.DataSource = _agreement.AllPostings.Where(p => p.Nominal == nominal).OrderBy(p => p.ValueDate).ThenBy(p => p.Id); postingGrid.DisplayLayout.Bands[0].PerformAutoResizeColumns(false, PerformAutoSizeType.AllRowsInBand, AutoResizeColumnWidthOptions.All);
Hope this all makes sense!!!
I'm guessing that there is an event that I need to hook up to whereby the calculated column is fully visible, but I can't work out what it is!!