Setting different border colors on an arbitrary set of GridView cells

1 Answer 111 Views
Dictionary GridView
Patgat
Top achievements
Rank 2
Iron
Iron
Iron
Patgat asked on 13 Feb 2023, 12:53 PM

Hi,

I am using a RadGridView to display user values related to each others in multiple ways.

I wish to periodically scan all cells to check the values and then flag them with a red or green cell border.

I keep all the cells status in a Dictionary<point, status> with point being the cell coordinates.

However, Idon't find a way to have all cells with a reference in the dictionary permanently showing the right border depending on its status.

I am using the cell_formatting event, but the border color disappear when cell is not current.

Here is some sample code


 private void gvLignesFacture_CellFormatting(object sender, CellFormattingEventArgs e)
    {
        // On décore la cellule selon son status
        Point cellCoordinates = new(e.CellElement.RowIndex, e.CellElement.ColumnIndex);
        if (DictOfGvCellStatusByCoordinates.TryGetValue(cellCoordinates, out var lookStatus))
        {
            switch (lookStatus)
            {
                case CtrlLook.Default:
                    e.CellElement.Font = GlobalVars.smallRegularFont;
                    e.CellElement.BorderColor = Color.Black;
                    break;

                case CtrlLook.Valid:
                    e.CellElement.Font = GlobalVars.smallBoldFont;
                    e.CellElement.BorderColor = Color.Green;
                    break;

                case CtrlLook.Incorrect:
                    e.CellElement.Font = GlobalVars.smallRegularFont;
                    e.CellElement.BorderColor = Color.Red;
                    break;
            }
        }
   }

How to do  this right ?

Many thanks for your answer

Patrick

 

 

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 13 Feb 2023, 01:15 PM

Hi, Patrick,

Please make sure that the CellElement.DrawBorder property is set to true to see the border element. The CellElement.BorderBoxStyle property also allows you to specify SingleBorder. 

Due to the UI virtualization in RadGridView, cell elements are created only for currently visible cells and are being reused during operations like scrolling, filtering, grouping and so on. In order to prevent applying the formatting to other columns' cell elements (because of the cell reuse), all customization should be reset for the rest of the cell elements. In other words, each "if" condition that applies some style settings, should have its "else" clause to reset the applied settings.

The following help article demonstrates how to properly use the CellFormatting event: 

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

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

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Patgat
Top achievements
Rank 2
Iron
Iron
Iron
commented on 15 Feb 2023, 12:22 PM

Hi Dess,

effectively, the routine setting this parameter wasn't called. My mistake.

My apologies for this.

It works ok

Thanks

Patrick

 

Tags
Dictionary GridView
Asked by
Patgat
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or