你好,我有一个dataGrid
,双击后会打开一个新的Window
,并填充一些TextBoxes
我的问题是Textboxes
想要显示短日期时显示日期和时间。
我已将SQL Server数据库严格配置为Date
,它显示了数据库中的短日期,所以我不确定为什么它在DateTime
中传递了Textbox
。
请帮助!
这是我为主窗口的代码:
private void dtGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
// User double clicks on DataGrid Row
// Open new Window
// Populate selected textboxes with selected datarow
DataGrid gd = (DataGrid)sender;
DataRowView row_selected = gd.SelectedItem as DataRowView;
var windowToOpen = new Window1();
if (gd != null)
{
// Textboxes
windowToOpen.txt_RowRecrd.Text = row_selected["DSP_ID"].ToString();
windowToOpen.txt_DateResolved.Text = row_selected["DATERSLVD"].ToString();
windowToOpen.txt_revcls.Text = row_selected["RateType"].ToString();
windowToOpen.Show();
}
}
这里是我的TextBoxes
之一的XAML:
<TextBox
x:Name="txt_DateResolved"
Width="110"
Height="26"
Margin="5,0,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Bottom"
Background="Transparent"
BorderBrush="Transparent"
BorderThickness="0"
Foreground="Black"
IsEnabled="True">
</TextBox>
由于在C#中没有Date
结构,所以只有DateTime
struct。您可以使用DateTime
方法设置DateTime的格式。您应该有一个DateTime实例,并可以在其上调用以下方法:
ToString()
或
dateTime.ToShortDateString()