Hi, I'm trying to perform a few operations on calculated columns in my UltraWinGrid, and they're not behaving quite as I'd hope. What I'm trying to do is create a couple of columns that are derived from other, hidden columns, and then sort by one and autofit the header to the other. However, at the time that I am performing these operations in my InitializeLayout event handler, I cannot get values for these columns, and I'm also having trouble finding an event that occurs with the timing I'm looking for. I've come up with a solution that involves the layout visibly moving around before the user's eyes, and I'm trying to avoid doing that.
But let me not put the cart before the horse. Here's a snippet of how I'm generating one of the columns, and what I'm trying to do with it:
#region Example code
//In the middle of the InitializeLayout event handler for my grid
//Leaving out some validation logic for my CalcManager cast
UltraCalcManager CalcManager = grid.CalcManager as UltraCalcManager;
CalcManager.DeferredCalculationsEnabled = false;
ColumnsCollection bandColumnsCollection = columnsToOrderBySortedByPriority[0].Band.Columns;
UltraGridColumn compositeDateColumn = bandColumnsCollection.Add("compositeDateColumn");
compositeDateColumn.Hidden = true;
compositeDateColumn.Formula = "<something complex that evaluates just fine after the first CalculationsCompleted tick>";
e.Layout.Bands[0].SortedColumns.Add(medDescriptionColumn, false); //This column is assigned previous to this snippet and sorts as expected e.Layout.Bands[0].SortedColumns.Add(doseColumn, false); //This column is assigned previous to this snippet and sorts as expected
e.Layout.Bands[0].SortedColumns.Add(compositeDateColumn, false);
#endregion Example code
The strategy that I wound up employing to try to perform this sort works, but whether I'm recalculating manually or asynchronously, the user sees the grid in its unsorted state, with null values in the cells of the column in question. Very quickly, the cells become populated, and then the sort occurs in full view of the user - and I'm a bit concerned about the performance implications of executing this continuously:
#region Current sorting mechanism (very similar to my column fitting mechanism in my other calculated column)
internal void EnableSortingOnCalculatedColumns(UltraGridBand bandContainingFormulaColumns) { EventHandler onCalculationsCompleted_refreshSort = (object refreshSortSender, EventArgs args) => { bandContainingFormulaColumns.SortedColumns.RefreshSort(true); }; CalcManager.CalculationsCompleted += onCalculationsCompleted_refreshSort; }
#endregion Current sorting mechanism (very similar to my column fitting mechanism in my other calculated column)
Could anyone help me figure out how to get this to behave as I expect?
Thanks!
Thanks to both Mike and Hristo for your help!
Hristo, it sounds like your suggestion is precisely what I'm doing. The issue is that, before the calculations are completed, the grid is being drawn, so the user is seeing the calculations performed visibly. After a very brief tic, the grid displays as I expect it to. I am attaching a screenshot that may describe the situation better.
Mike, I may well be running an older version of the controls - however, I have absolutely no power to pressure the company I work for to upgrade. The assembly I'm running out of is Infragistics4.Win.UltraWinGrid.v13.2.dll, v13.2.20132.2023. Does a workaround exist for the version that I am currently running?
Hello ,
Have you tried to set CalcFrequency to Synchronous, in InitializeLayout event
http://help.infragistics.com/Help/Doc/WinForms/2012.2/CLR4.0/HTML/Infragistics4.Win.UltraWinCalcManager.v12.2~Infragistics.Win.UltraWinCalcManager.CalcFrequency.html
does this helps you ?
I am waiting for your feedback.
It is not necessary to add your calculated column to the corresponding data base table, but you could generate it with the select query which populates your data table or after the corresponding ADO.NTE table was populated to add additional column which is not mapped and to add the Expression you need, i.e. something like:
dt.Columns.Add("Exp", typeof(string)).Expression = "IIF([wkr_firstName] = null And [wkr_lastName] = null, IIF([o_enteredBy] = null, ' ', [o_enteredBy]),[wkr_firstName] + ' ' + [wkr_mi] + ' ' + [wkr_lastName] + ', ' + [wkr_signatureTitle])";
so on this way calculation will be made to underling data source (not in data base, only with in ADO.NET DataTabel). Anpther options which I could suggest you is to handle InitializeRowEvent and to calculate the value of Worker column cells.
Please let me know if you have any further questions.
It would never have occurred to me to modify the DataTable via C#. I'm not sure that that fits my company's policy either - and I don't have a great way to modify the DataTable and hide the aggregated columns in one function call, which is something I'm really trying to accomplish here.
I'm not seeing a great way to force calculation on the InitializeRow event. How do I accomplish this?
I've already spent more time trying to coax this behavior out of this column than I have spent working on the entire rest of this ticket. My next attempt will be my last - failing success, I'll simply stop trying to find a clever solution and calculate these columns in SQL.
You misunderstood the approached with the InitializeRow event. In this event you should calculate the value for the Calculation column for the current row and to assign this value to the corresponding cell.
This worked great in the sample project that we've been kicking around. It gave me a great entry point for other people to reuse my code, it performed admirably, and it gave me the precise results that I wanted. Unfortunately, in my company's product, the custom grid that we have built over the Infragistics grid uses have overridden some events, and this causes the InitializeRow event to first be fired before the columns collection is populated.
I've spent much more time on this than I should have, so I'm abandoning any further attempts to work with this from the frontend. Thanks for your help!
Please let me know if you need may further assistance on this.
Thank you for using Infragistics Components.