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

[Solved] How to Change Border of a given Row?

5 Answers 203 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Alfa
Top achievements
Rank 1
Alfa asked on 27 Nov 2009, 11:08 AM
Hi,
I am trying to set the color and thickness of the row.
Here is my code
private void SetSolidBorder(GridViewRow Row, Color BorderColor, int BorderThickness)
{
try
{
Row.BorderBrush = new SolidColorBrush(BorderColor);
Row.BorderThickness = new Thickness(BorderThickness);
}
catch (Exception ex)
{
throw ex;
}
}
and i am calling it like

GridViewRow row= this.ItemContainerGenerator.ContainerFromItem(this.CurrentItem) as GridViewRow;
SetSolidBorder(Row, Colors.Purple , 10);
But it is setting neither color nor thickness.

Rgds
Alfa

5 Answers, 1 is accepted

Sort by
0
Tsvyatko
Telerik team
answered on 30 Nov 2009, 04:10 PM
Hello Alfa,

You can change the border thickness and the brush by directly accessing the visual element using  the following code:

Border rowBorder = Row.ChildrenOfType<Border>().Where(c => c.Name == "PART_RowBorder").First();

Alternatively if you want to change all rows' border you can use the custom row template for the gridview.

Let me now if this works for you.

Kind regards,
Tsvyatko
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Alfa
Top achievements
Rank 1
answered on 01 Dec 2009, 11:52 AM
Hi,

Thank you.
The code it working but one issue.
It is changing the border of the "RowIndicator" column too.

Along with that is there any way of restore the original border.

Actually, I am using border to show the error and want to restore the original border if the error is rectified.

Rgds
Alfa

0
Accepted
Tsvyatko
Telerik team
answered on 03 Dec 2009, 10:12 AM
Hello Alfa,

In your case you can take advantage of another visual element in the row designed specially for validation.

It can be acquired using the following code:

Rectangle rect = e.Row.ChildrenOfType<Rectangle>().Where(c => c.Name == "InvalidBorder").First() as Rectangle;

It is displayed when trying to add invalid value in a cell. If it need to be shown manually by setting rectangle opacity to 1.

Additionally you can customize the grid row style or just control the visual elements from code behind.

I am attaching sample project illustrating the solution.

If you have any more questions do not hesitate to contact us.


Regards,
Tsvyatko
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Alfa
Top achievements
Rank 1
answered on 07 Dec 2009, 07:50 AM
Hi,

Is this visual element is available for cell too?

Rgds
Alfa
0
Tsvyatko
Telerik team
answered on 09 Dec 2009, 05:46 PM
Hi Alfa,

 The element you are looking for is accessed using the following code:

Border border= e.Cell.ChildrenOfType<Border>().Where(c => c.Name == "ValidationErrorElement").First() as Border;

Keep in mind that this element can be accessed only in cell edit mode.

However there is alternative solution  - you can use CellValidating event to validate the cell content before committing it. Check this demo for reference.

If these solutions does not fulfill you requirements you can define your own CellTemplate adding border elements of your taste.

I hope this helps.

Regards,
Tsvyatko
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
GridView
Asked by
Alfa
Top achievements
Rank 1
Answers by
Tsvyatko
Telerik team
Alfa
Top achievements
Rank 1
Share this question
or