簡體   English   中英

如何從.cs文件在c#中的DataTable單元格中對齊文本

[英]How to align text in DataTable cell in c# from .cs file

我已經創建了一個表

 DataTable table= new DataTable();

我在其中逐行添加數據。但是在第一行中,第一列是字符串,其他列是數字。 我想將第一列向左對齊,將數字向右對齊。添加到行中時,有什么方法可以對齊單元格?

<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 }"

告訴我它是否在尋找什么?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM