如何在.cs文件中的c#中的DataTable单元格中对齐文本

时间:2014-07-02 07:32:52

标签: c# wpf xaml datatable

我创建了一个表

 DataTable table= new DataTable();

其中我逐行添加数据。但是在一行中,第一列是字符串,其他列是数字。 我想将第一列左对齐,数字右对齐。是否有任何方法可以在添加到行中时对齐单元格?

1 个答案:

答案 0 :(得分:-1)

<Window.Resources>

编写以下代码:

<Style x:Key="RightCellStyle" TargetType="{x:Type telerik:GridViewCell}">
    <Setter Property="HorizontalAlignment" Value="Right">
    </Setter>

</Style>

<Style x:Key="LeftCellStyle" TargetType="{x:Type telerik:GridViewCell}">
    <Setter Property="HorizontalAlignment" Value="Left">
    </Setter>
</Style> 

<telerik:RadGridView.Columns>

编写以下代码,即将样式设置为单元格

<telerik:GridViewDataColumn Header="Your header" CellStyle="{StaticResource LeftCellStyle }"></telerik:GridViewDataColumn>

和你要正确对齐的单元格一样;刚设置

CellStyle="{StaticResource RightCellStyle }"

告诉我你是否在寻找它?