Reputation: 11
Can anyone help me in changing foreground color & text of a silverlight telerik gridview cell from codebehind.
My actual requirement is,
I have a dataset which contains data.Few columns have data with prefix "r_". Now I need to show this data in grid. And the columns which has prefix "r_" should be displayed in red color. and I should also remove that prefix before showing it in grid.
Ex: MyDataSet
Column1 Column2 Column3
Test1 Test2 Test3
Test4 r_Test5 Test6
r_Test7 Test8 r_Test9
In the above example r_Test5,r_Test7 & r_Test9 should be displayed as Test5,Test7 & Test9 respectively, but in red color.
Upvotes: 0
Views: 441
Reputation: 11
Never Mind. found a solution for this.
private void dgBank_CellLoaded(object sender, Telerik.Windows.Controls.GridView.CellEventArgs e)
{
if (e.Cell is GridViewCell && ((e.Cell.Column).Header== "Column_1") || ((e.Cell.Column).Header== "Column_2") || ((e.Cell.Column).Header== "Column_3"))
{
TextBlock txt = e.Cell.Content as TextBlock;
txt.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 0, 0));
if (txt.Text.StartsWith("r_"))
{
var cell = e.Cell;
txt.Foreground = new SolidColorBrush(Color.FromArgb(120, 255, 0, 0));
txt.Text = txt.Text.Replace("r_", string.Empty);
}
}
}
Thanks.
Upvotes: 1