Unable to apply formatting for HeaderRow

1 Answer 106 Views
GridView
Paul
Top achievements
Rank 1
Paul asked on 04 Oct 2022, 08:39 PM

Using available examples, applying different formatting to row header does not work as the RowElement never comes in as a GridTableHeaderRowElement. New rows are formatting correctly.

 

 private void RadGridView1_RowFormatting(object sender, RowFormattingEventArgs e)
        {
            try
            {
                if ((string)e.RowElement.RowInfo.Tag == "new row")
                {
                    e.RowElement.DrawFill = true;
                    e.RowElement.BackColor = System.Drawing.Color.LightCyan;
                    e.RowElement.ForeColor = System.Drawing.Color.Black;
                    e.RowElement.Text = "New";
                    e.RowElement.TextAlignment = System.Drawing.ContentAlignment.TopLeft;
                }
                else if (e.RowElement is GridTableHeaderRowElement)
                {
                    e.RowElement.DrawFill = true;
                    e.RowElement.BackColor = System.Drawing.Color.Navy;
                    e.RowElement.NumberOfColors = 1;
                    e.RowElement.ForeColor = System.Drawing.Color.White;
                    e.RowElement.Text = "";
                }
                else
                {
                    e.RowElement.ResetValue(LightVisualElement.DrawFillProperty, Telerik.WinControls.ValueResetFlags.Local);
                    e.RowElement.ResetValue(LightVisualElement.BackColorProperty, Telerik.WinControls.ValueResetFlags.Local);
                    e.RowElement.ResetValue(LightVisualElement.NumberOfColorsProperty, Telerik.WinControls.ValueResetFlags.Local);
                    e.RowElement.ResetValue(LightVisualElement.ForeColorProperty, Telerik.WinControls.ValueResetFlags.Local);
                    e.RowElement.Text = "";
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Uncaught error in {System.Reflection.MethodBase.GetCurrentMethod().Name}: {ex.Message}");
            }
        }

1 Answer, 1 is accepted

Sort by
1
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 05 Oct 2022, 05:54 AM

Hello, Paul,

Please have in mind that the CellFormatting and RowFormatting events are fired only for the data cells/rows. If you want to style the header cells/rows as well, feel free to use the ViewCellFormatting and ViewRowFormatting events which are fired for the data and non-data rows. More information about the events is available here:

https://docs.telerik.com/devtools/winforms/controls/gridview/cells/formatting-cells#formatting-non-data-cells

https://docs.telerik.com/devtools/winforms/controls/gridview/rows/formatting-rows 

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
GridView
Asked by
Paul
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or