我试图在DataGrid
中动态添加DateTime
(7/30/2011)列。我将上传我手动制作的网格屏幕截图。我想制作一个范围组合框。因此,如果用户选择2周,那么网格会逐日添加列。动态添加DataGrid日期时间列
回答
你可以做这样的事情
private void AddColumns(GridView gv, string[] dateColumns)
{
for (int i = 0; i < dateColumns.Length; i++)
{
gv.Columns.Add(new GridViewColumn
{
Header = dateColumns[i],
DisplayMemberBinding = new Binding(String.Format("[{0}]", i))
});
}
}
这可以叫上了ComboBox OnSelectionChanged()
你也可以使用一个DataTemplate正确显示的列:
<DataTemplate DataType="{x:Type DateTime}">
<TextBlock Text="{Binding StringFormat={0:d}}" />
</DataTemplate>
不,只是调整y我们对您的需求的StringFormat:
基本是Binding="{Binding date, StringFormat={}{0:dd/MM/yyyy}}"
以及我如何创建日期列? –
@酸查看编辑 –
感谢重播,但它对我来说很不清楚:(我必须这样做?:绑定=“{绑定日期,StringFormat = {} {0:dd/MM/yyyy}}” –
- 1. SQL添加两列(日期时间)
- 2. 添加日期至日期时间
- 3. 添加日期时间(秒)
- 4. PHP添加日期时间
- 5. 添加到日期时间
- 6. 将日期时间间隔添加到日期时间
- 7. 动态添加列到WPF中的DataGrid
- 8. 在Flex中动态添加列到datagrid
- 9. 添加时间反馈日期时间
- 10. 动态添加Tabitems与Datagrid
- 11. Datagrid动态添加数据
- 12. 动态添加DataGrid中
- 13. SQL Server:将日期时间添加到日期时间字段?
- 14. 日期时间添加时间段而不显示日期VB
- 15. 添加日期参数和时间参数单日期时间
- 16. SQL添加日期时间添加小时添加分钟
- 17. 日期时间添加小时
- 18. JavaScript/jQuery +日期时间选择器:动态添加的输入不显示激活日期时间选择器。
- 19. 添加日期列
- 20. Gnuplot添加任意秒列到日期/时间列
- 21. 格式动态日期时间
- 22. SQL动态变化的日期时间
- 23. 动态日期时间SELECT查询
- 24. 将时间跨度添加到日期?
- 25. 将日期/时间添加到JFreeChart图
- 26. Visual Basic添加到时间戳日期
- 27. Java如何添加时间和日期
- 28. 添加前导零日期时间C#
- 29. 添加分钟(时间)日期
- 30. 添加日期时间选取器?
提示:请确保您使用浏览器拼写检查。将其设置为英语。 –