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

Selected cells border color

6 Answers 204 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Zerka
Top achievements
Rank 1
Zerka asked on 24 Jan 2011, 12:18 PM

Hi
My code to change the back color of all the selected cells is working fine but It can not change the border color of all the selected cells of the grid. What I am doing wrong?

Here is my code:

private void dtgCpr_ViewCellFormatting(object sender, CellFormattingEventArgs e)
        {
            e.CellElement.DrawBorder = true;
            if (e.CellElement.IsSelected)
            {
                e.CellElement.BorderColor = Color.Red;
                e.CellElement.BackColor = Color.SeaShell;
            }
        }

Thanks

Regards

6 Answers, 1 is accepted

Sort by
0
Richard Slade
Top achievements
Rank 2
answered on 24 Jan 2011, 12:39 PM
Hi Michael,

For the selected border colour, the following code is enough to change it when the cell is selected.

private void radGridView1_ViewCellFormatting(object sender, CellFormattingEventArgs e)
{
    e.CellElement.DrawBorder = true;
    e.CellElement.BorderColor = Color.Red;
}

hope that helps
Richard
0
Zerka
Top achievements
Rank 1
answered on 24 Jan 2011, 01:21 PM
Hi Richard,

Actually my grid has MultiSelect = true and SelectionMode = CellSelect. So user can select multiple cells at a time. But the my code and yours code is changing the border color of just first cell. How can I change the border color of all selected cells?

But backcolor of cell is working fine and it is changing color for all selected cells.

Reagrds
0
Richard Slade
Top achievements
Rank 2
answered on 24 Jan 2011, 02:18 PM
Hi again,

Ok, I see. In that case, please can you add the following instead.

e.CellElement.BorderColor = Color.Red;
if (e.CellElement.IsSelected)
{
    e.CellElement.BorderBoxStyle = BorderBoxStyle.SingleBorder;
}
else
{
    e.CellElement.BorderBoxStyle = BorderBoxStyle.FourBorders;
}

You might also want to consider using the CellFormatting event rather than ViewCellFormatting as ViewCellFormatting fires for all cells, and not just data cells.
Hope that helps
Richard
0
Zerka
Top achievements
Rank 1
answered on 25 Jan 2011, 09:15 AM
Hi Richard,

Your code is working fine if user selects multiple cells through keyboard. But it is not working if user selects multiple cells with mouse. In this case only few cells are changing border color. Can you please help me about that?

Thanks

Regards
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 25 Jan 2011, 10:26 AM
Hi Michael,

Please can you try this
e.CellElement.BorderColor = Color.Red;
if (e.CellElement.IsSelected)
{
    e.CellElement.BorderBoxStyle = BorderBoxStyle.SingleBorder;
    e.CellElement.BorderGradientStyle = GradientStyles.Solid;
    e.CellElement.BorderWidth = 2;
}
else
{
    e.CellElement.BorderBoxStyle = BorderBoxStyle.FourBorders;
}

Thanks
Richard
0
Zerka
Top achievements
Rank 1
answered on 25 Jan 2011, 10:55 AM
Thanks! It works.

Regards
Tags
GridView
Asked by
Zerka
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Zerka
Top achievements
Rank 1
Share this question
or