This is a migrated thread and some comments may be shown as answers.

RowFormatting Event Unreliable?

3 Answers 57 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Greg
Top achievements
Rank 1
Greg asked on 29 May 2014, 09:35 PM
We are using a RadGridView to display data in a small area, only two rows are visible at any given time with the third row partially visible.  Using the RowFormatting event handler, we set the forecolor to reflect rows that contain 'inactive' or 'invalid' records based on columns in the underlying data.  Generally this works fine.  But when there are more than three rows in the grid and some of those rows are not visible, the forecolor change is not reliable.  For example, if the first three rows are 'valid' and the fourth row is 'invalid', all appears correct when the grid is initially displayed and the user scrolls down to the fourth row.  The 'invalid' row has the forecolor changed to gray.  But when the fourth is selected and the user then scrolls back to the first row, the first row now shows as 'invalid' (forecolor = gray) even though the data has not changed and the other rows still display the same as before.  From that point on the first row displays incorrectly until the data is refreshed.  Sometimes this occurs even if the last row is not selected, just scrolling from top to bottom and back.

        private void grdEFT_RowFormatting(object sender, RowFormattingEventArgs e)
        {
                if (e != null &&
                    e.RowElement.RowInfo != null &&
                    e.RowElement.RowInfo.DataBoundItem is DataRowView)
                {
                    DataRow drEFT = ((DataRowView)e.RowElement.RowInfo.DataBoundItem).Row;
                    DataRow drAPM = drEFT.GetParentRow(this.rAutopayDS.Relations["AssociatePaymentMethodEFTPaymentMethodInfo"]);

                    if (drAPM != null)
                    {
                        // Show the row as inactive if it is not active.
                        if (!(bool)drAPM["Active"] ||
                            !(bool)drEFT["Valid"])
                        {
                            e.RowElement.ForeColor = System.Drawing.SystemColors.ControlDark;
                        }
                        else
                        {
                            e.RowElement.ResetValue(LightVisualElement.FontProperty, ValueResetFlags.Local);
                        }
                    }
                    else
                    {
                        e.RowElement.ResetValue(LightVisualElement.FontProperty, ValueResetFlags.Local);
                    }
                }
        }

Thanks,
Greg Swope






3 Answers, 1 is accepted

Sort by
0
Greg
Top achievements
Rank 1
answered on 30 May 2014, 02:21 PM
Never mind.  After much trial and error, we found the cause.  Resetting the font property would have no effect since it had not changed.  Altered the code to reset the forecolor property instead and now all is well.

 e.RowElement.ResetValue(LightVisualElement.FontProperty, ValueResetFlags.Local);

changed to

 e.RowElement.ResetValue(LightVisualElement.ForeColor, ValueResetFlags.Local);


0
Greg
Top achievements
Rank 1
answered on 30 May 2014, 02:22 PM
Sorry, that last line should have been;

e.RowElement.ResetValue(LightVisualElement.ForeColorProperty, ValueResetFlags.Local);
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 03 Jun 2014, 01:02 PM
Hello Greg,

Thank you for writing.

I am glad that the issue you were facing is now resolved. In addition, I suppose that our Formatting Rows help article would be quite useful about this topic.

I hope this information helps. Should you have further questions, I would be glad to help.

Regards,
Desislava
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
GridView
Asked by
Greg
Top achievements
Rank 1
Answers by
Greg
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or