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,
I am glad that you find my suggestion helpful and were able to solve your issue.
Thank you for using Infragistics components.
Regards,
Monika Kirkova,
Infragistics
Hi Monika,
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.
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.
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...
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.
Thanks.