wpf中datagrid中如何嵌套? datagrid中自动生成行时,怎么在某个单元格中嵌套DateTimePicker控件。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 是自动生成列吧??某个单元格嵌套DateTimePicker控件??是某列放置的是DateTimePicker控件吧??首先你要知道如何动态生成列,然后指定动态生成的第几列放置DateTimePicker控件就可以了。#region 动态生列方法 /// <summary> /// 产生模板列(带格式化时间) /// </summary> /// <param name="headername"></param> /// <param name="bindingname"></param> /// <param name="width"></param> /// <returns></returns> public DataGridTemplateColumn CreateDateTimeTemplate(string headername, string bindingname, double width) { DataGridTemplateColumn templateColumn = new DataGridTemplateColumn(); templateColumn.Header = headername; StringBuilder CellTemp = new StringBuilder(); CellTemp.Append("<DataTemplate "); CellTemp.Append("xmlns='http://schemas.microsoft.com/winfx/"); CellTemp.Append("2006/xaml/presentation' "); CellTemp.Append("xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' "); CellTemp.Append("xmlns:local='clr-namespace:spjl1"); CellTemp.Append(";assembly=spjl1'>"); CellTemp.Append("<Grid>"); CellTemp.Append("<Grid.Resources>"); CellTemp.Append("<local:DateTimeConverter x:Key='DateTimeConverter' />"); CellTemp.Append("</Grid.Resources>"); CellTemp.Append("<TextBlock "); CellTemp.Append("Text = '{Binding " + bindingname + ", "); CellTemp.Append("Converter={StaticResource DateTimeConverter}}' "); CellTemp.Append("Margin='4'/>"); CellTemp.Append("</Grid>"); CellTemp.Append("</DataTemplate>"); templateColumn.CellTemplate = (DataTemplate)XamlReader.Load(CellTemp.ToString()); templateColumn.HeaderStyle = (Style)Resources["DataGridHeaderStyle"]; templateColumn.CellStyle = (Style)Resources["DataGridCellStyle"]; templateColumn.CanUserSort = true; templateColumn.IsReadOnly = true; templateColumn.Width = new DataGridLength(width); return templateColumn; } /// <summary> /// 创建DataGridTextColumn模板列 /// </summary> /// <param name="columnBindName">需要绑定的字段名</param> /// <param name="columnHeaderName">模板列的Header</param> /// <param name="width">模板列的宽度</param> /// <returns></returns> public DataGridTextColumn CreateDataGridTextColumn(string columnBindName, string columnHeaderName, double width) { DataGridTextColumn dgtextColumn = new DataGridTextColumn(); dgtextColumn.Binding = new Binding(columnBindName); dgtextColumn.Header = columnHeaderName; dgtextColumn.HeaderStyle = (Style)Resources["DataGridHeaderStyle"]; dgtextColumn.CellStyle = (Style)Resources["DataGridCellStyle"]; dgtextColumn.IsReadOnly = true; dgtextColumn.Width = new DataGridLength(width); return dgtextColumn; } #endregion http://blog.csdn.net/taomanman/article/details/6741599 ,希望对你有帮助 新手求教treeview用法 时间判断如何做? 怎么得到具体日期 引用存储过程中的输出参数出错,请帮忙看看,谢谢 求助!!!怎么让Datagridview 的某一单元格处于编辑状态???(winform中) 怎么在C#中的listbox或listview中使用进度条 请问:一条记录,放在数据库里效率高?还是放在XML里效率高? 不使用ArrayList在C#如何使用动态数组 关于终端机的问题! 树的问题 C#与485串行通信问题 路径问题
#region 动态生列方法
/// <summary>
/// 产生模板列(带格式化时间)
/// </summary>
/// <param name="headername"></param>
/// <param name="bindingname"></param>
/// <param name="width"></param>
/// <returns></returns>
public DataGridTemplateColumn CreateDateTimeTemplate(string headername, string bindingname, double width)
{
DataGridTemplateColumn templateColumn = new DataGridTemplateColumn();
templateColumn.Header = headername;
StringBuilder CellTemp = new StringBuilder();
CellTemp.Append("<DataTemplate ");
CellTemp.Append("xmlns='http://schemas.microsoft.com/winfx/");
CellTemp.Append("2006/xaml/presentation' ");
CellTemp.Append("xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' ");
CellTemp.Append("xmlns:local='clr-namespace:spjl1");
CellTemp.Append(";assembly=spjl1'>");
CellTemp.Append("<Grid>");
CellTemp.Append("<Grid.Resources>");
CellTemp.Append("<local:DateTimeConverter x:Key='DateTimeConverter' />");
CellTemp.Append("</Grid.Resources>");
CellTemp.Append("<TextBlock ");
CellTemp.Append("Text = '{Binding " + bindingname + ", ");
CellTemp.Append("Converter={StaticResource DateTimeConverter}}' ");
CellTemp.Append("Margin='4'/>");
CellTemp.Append("</Grid>");
CellTemp.Append("</DataTemplate>");
templateColumn.CellTemplate = (DataTemplate)XamlReader.Load(CellTemp.ToString());
templateColumn.HeaderStyle = (Style)Resources["DataGridHeaderStyle"];
templateColumn.CellStyle = (Style)Resources["DataGridCellStyle"];
templateColumn.CanUserSort = true;
templateColumn.IsReadOnly = true;
templateColumn.Width = new DataGridLength(width);
return templateColumn;
}
/// <summary>
/// 创建DataGridTextColumn模板列
/// </summary>
/// <param name="columnBindName">需要绑定的字段名</param>
/// <param name="columnHeaderName">模板列的Header</param>
/// <param name="width">模板列的宽度</param>
/// <returns></returns>
public DataGridTextColumn CreateDataGridTextColumn(string columnBindName, string columnHeaderName, double width)
{
DataGridTextColumn dgtextColumn = new DataGridTextColumn();
dgtextColumn.Binding = new Binding(columnBindName);
dgtextColumn.Header = columnHeaderName;
dgtextColumn.HeaderStyle = (Style)Resources["DataGridHeaderStyle"];
dgtextColumn.CellStyle = (Style)Resources["DataGridCellStyle"];
dgtextColumn.IsReadOnly = true;
dgtextColumn.Width = new DataGridLength(width);
return dgtextColumn;
}
#endregion http://blog.csdn.net/taomanman/article/details/6741599 ,希望对你有帮助