【发布时间】:2013-08-13 18:51:13
【问题描述】:
我正在显示一些关于 DataGrid 中已经存在的案例的信息。
在我的MS Access 数据库中,所有日期都以DateTime 格式存储,如下所示:dd/MM/yyyy。
问题是当程序运行时显示DataGrid时,格式变为MM/dd/yyyy。
让我迷失的是,当我在MessageBox 中显示相关单元格的内容时,就在将DataTable 分配给DataGrid 之前,我得到了正确的格式(dd/MM/yyyy )。
我尝试更改DateTimeMode,但显示的格式相同。
有人有任何提示可以解决这个问题吗?我给你下面的代码:
数据表 temp = dt.Clone();
temp = (from nardin in dt.AsEnumerable().Distinct()
where nardin["NUMERO CLIENT"].ToString() == _centerID.ToString()
select nardin).CopyToDataTable();
RemoveDuplicates(temp, "NUMERO DOSSIER");
foreach (DataRow row in temp.Rows)
{
MessageBox.Show(row["DATE INTERVENTION"].ToString()); //this gives me the DateTime format i'd like to display
}
existingCase.ItemsSource = temp.AsDataView(); //once assigned to the DataGrid the DateTime format is not the same as above
实际上 DataGrid 在 xaml 文件中是这样声明的:
<DataGrid SelectionUnit="FullRow" SelectedItem="{Binding SelectedBI, Mode=TwoWay}" AutoGenerateColumns="True" Margin="0,167,12,167" Name="existingBI" Width="588" HorizontalAlignment="Right">
<DataGrid.RowStyle>
<Style TargetType="{x:Type DataGridRow}">
<EventSetter Event="MouseDoubleClick" Handler="resultDataGridBI_MouseDoubleClick"/>
</Style>
</DataGrid.RowStyle>
</DataGrid>
我将 DataTable 绑定到:existingCase.ItemsSource = temp.AsDataView();
提前,谢谢!
【问题讨论】: