簡體   English   中英

更改數據網格中的類型列

[英]Change type column in datagrid

MySqlCommand cmd = new MySqlCommand(query, conn);
dt.Load(cmd.ExecuteReader());
source.DataSource = dt;
dataGrid1.ItemsSource = source;

在我的數據網格中,我想將DateTime的列類型更改為String ,該怎么做?


來源是

System.Windows.Forms.BindingSource source = new System.Windows.Forms.BindingSource();

您可以為此定義DateTime值的DataTemplate

<DataGrid> 
    <DataGrid.Resources> 
        <DataTemplate DataType="{x:Type DateTime}"> 
            <TextBlock Text="{Binding StringFormat={0:d}}"  /> 
        </DataTemplate> 
    </DataGrid.Resources> 
    ... 
</DataGrid> 

參考- 需要在動態構建的WPF DataGrid中格式化日期

暫無
暫無

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

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