如何将所选日期转换为网格中的短日期类型?我只想表明日期,而不是时间。
vasketidssystemEntities forbindelse = new vasketidssystemEntities();
public OwnReservations()
{
InitializeComponent();
}
private void Grid_Loaded(object sender, RoutedEventArgs e)
{
ObjectQuery<reservation> reservationer = forbindelse.reservations;
var query =
from res in reservationer
where res.resident_ID == 17
orderby res.date
select new { res.date, res.hourofday, res.resident_ID };
datagrid1.ItemsSource = query.ToList();
答案 0 :(得分:2)
您可以编辑要格式化的列的列格式,如下所示:
datagrid1.Columns[0].DefaultCellStyle.Format = "d";
在设置datagrid1的ItemsSource后执行此操作。
答案 1 :(得分:0)
您可以执行this SO question中的答案,即:
reservationer.Select(a => new { a.date, a.hourofday, a.resident_ID })
.AsEnumerable()
.Select(p => new
{ date = p.date.ToShortDateString(),
hourofday = p.hourofday,
resident_ID = p.resident_ID
});