I am working on bringing applications with older components to the 2020.1 fold .. I have the following problem that I need to resolve.
On one hierarchical grid there is a need to format cells as the underlying data is floating point but only one row actually need to show decimals while the rest of the data should be whole numbers…. In an old application that was addressed by assigning delegate to the GridView.Columns[i].FormatFieldMethod that actually return the correct formatting string. It worked fine.. In new components it blows up if data on the grid was updated… If you can have a look and advise how to address the issue.
Here steps to recreate :
2. Click Post button, page get reposted, all the same.
3. Change some value in the a5 or a6 column on the main grid. It blows up, as somehow the lr4whdg reference is not there .. it also skips lr4whdg_RowUpdating event.. It does not skip it and works fine if data on the child grid updated..
WHG.zip
Hello Michael,
After investigating this further, I determined that the behavior is observed because the currentRow variable gets higher than the number of rows in the grid. What I could suggest is checking whether the row with index currentRow is not null in the FormatTotalField method as follows:
protected string FormatTotalField(ControlDataField field, object val)
{
if (this.lr4whdg.Rows[currentRow]!= null && (string)this.lr4whdg.Rows[currentRow].Items[1].Value == "TAXRATE")
. . .
}
Additionally the “RowUpdatingEvent” is fired when the Post_Back takes place, which is the default behavior when BatchUpdating is enabled.
Please let me know if you need any further information regarding this matter.
Regards,
Monika Kirkova,
Infragistics
Hi Monika, unfortunately thing a bit more complicated. To be fair I tried to use yours if statement and it did not work the same way with the same error.. that was expected as lr4whdg somehow does not exist at that moment...
Here couple of more consideration to check.. In old components ( 2013.2) that I am trying to leave as they not supported the following sequence of events take place:
Page_Load, Page_LoadComplete, Page_PreRender and then FormatTotalField is called for every row & column
This sequence repeated on every post back unless some data was updated .. if it was then the following happening :
Page_Load, lr4whdg_RowUpdating Page_LoadComplete, Page_PreRender and then FormatTotalField is called for every row & column .. In that version (2013.2) at this point when FormatTotalField the lr4whdg having reference to the grid object and everything works smoothly.
In new, supported components (2020.1) the sequence after update is broken : FormatTotalField starts getting calls right after Page_Load and at this point throwing exception on the first call (see image below) .. While it is probably does not matter , if data changed in the child grid.. it works ok, probably because it does not need formatting..
Please try to run the poc project that I uploaded and help me to find solution.. if you would see any other way to dynamically format cells , that is fine..but I would prefer to find fix for the existing approach.
I need it to apply formatting just for some limited number of cells in one row..
Thanks.
What I could suggest is calling “FormatTotalField” in a method bound to the DataBound event instead of the Page_LoadComplete. By adding the method in the dataBound event no exception would be thrown because the data is already bound to the grid:
<ig:WebHierarchicalDataGrid ID="lr4whdg" runat="server" . . . OnDataBound="lr4whdg_DataBound">
IrR4Data.aspx.cs:
protected void lr4whdg_DataBound(object sender, EventArgs e)
for (int i = FirstDataColumnNo_MainGrid ; i < lr4whdg.GridView.Columns.Count; i++)
lr4whdg.GridView.Columns[i].FormatFieldMethod = new FormatRecordItemValue(FormatTotalField); // to handle rate row
Please let me know if you need any further information regarding this matter
Hi Monika, while it seems like started to work with some complications because actual grid is dynamic in terms of columns.. wonder if there is another approach to format some cells in one particular row, without this global var keeping track of the current row.
Hi Monika,
Still not out of the wood yet.. Here is the issue.. Firstly - I need to format cells in one row only as decimals (see picture) ..
I moved delegate assignment into lr4whdg_DataBound but it is still blowing up on updates as I need to have DataBind() in the lr4whdg_RowUpdating as in the application dataset getting updates.. my understanding is that method assigned to FormatFieldMethod is column level, and seems like it is getting fired for every cell in the row..
If nothing done and update happening on the postback, it adds number of times it gets fired ( if you comment out
if (currentRow == this.lr4whdg.Rows.Count) { currentRow = this.lr4whdg.Rows.Count - 1; }
it will blow up as number of rows will go over this.lr4whdg.Rows.Count - 1 ..
Somehow it work correctly on the initial load but get off the track on the postback with updates.. Somehow it did work without issues with old components but now it stopped.. can you advise how to deal with this scenarios.. may be there is a way how to apply formatting differently.. again all I need is to format all numbers in one row as decimals.. and the rest should be whole numbers "{0:N0}" .... attached code that I used to show pictures ..
lrR4Data.zip
After update...
What I could suggest in order to format all cells in certain row is to bind a method to the OnRowInitialized event and if the current row is the “TaxRate” row, new value is set to all cells:
<ig:WebHierarchicalDataGrid ID="lr4whdg" runat="server" . . . OnInitializeRow="lr4whdg_InitializeRow">
Default.aspx.cs
protected void lr4whdg_InitializeRow(object sender, RowEventArgs e)
if (e.Row.Items[1].Value.ToString() == "TAXRATE")
for (int i = 0; i < e.Row.Items.Count; i++)
var a = e.Row.Items[i].Column.Type.Name;
if (e.Row.Items[i].Column.Type.Name == "Double")
e.Row.Items[i].Text = string.Format("{0:N5}", e.Row.Items[i].Value);
By adding the suggested approach, the FormatFieldMethod should not be used.
Please let me know if you need additional information regarding this matter.
I am glad that you find my suggestion helpful and were able to solve your issue.
Thank you for using Infragistics components.
Thanks a lot for your help .. FormatFieldMethod should not ever being used as it was really ugly solution for the very simple problem... Your last suggestion works fine.. Thank you.