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

Setting TextAlignment of GridViewExpressionColumn at Runtime

2 Answers 140 Views
GridView
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
Veteran
David asked on 13 Jan 2021, 10:20 AM

Hi

I'm attempting to set the TextAlignment property of a GridViewExpressionColumn at runtime. The property is set correctly but the change is not reflected in the grid. The same change to a GridViewDataColumn works as I would expect - the alignment is set visually on the screen straight away.

var col = this.RadGridView.Columns[0];
col.TextAlignment = TextAlignment.Right;

 

I have found that it the column is removed and re-inserted it will work correctly:

var col = this.RadGridView.Columns[0];
 
this.RadGridView.Columns.Remove(col);
 
col.TextAlignment = TextAlignment.Right;
 
this.RadGridView.Columns.Insert(0, col);

 

 

Is this a bug? Or am I missing something?

 

Regards

 

Dave

 

 

2 Answers, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 18 Jan 2021, 07:34 AM

Hello David,

This is an issue with the GridViewExpression column. I've logged it in the feedback portal where you can track its status. Also, you can find your Telerik points updated.

To work this around, you can define a CellTemplate for the column and set the TextAlignment property in the element inside the template. For example:

<telerik:GridViewExpressionColumn.CellTemplate>
	<DataTemplate>
		<TextBlock Text="{Binding}" 
				   TextAlignment="{Binding RelativeSource={RelativeSource AncestorType=telerik:GridViewCell}, Path=Column.TextAlignment}"  />
	</DataTemplate>
</telerik:GridViewExpressionColumn.CellTemplate>

You can also check the attached project. I hope this helps.

Regards,
Martin Ivanov
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/.

0
David
Top achievements
Rank 1
Veteran
answered on 26 Jan 2021, 05:25 PM
Thanks, Martin.
Tags
GridView
Asked by
David
Top achievements
Rank 1
Veteran
Answers by
Martin Ivanov
Telerik team
David
Top achievements
Rank 1
Veteran
Share this question
or