WPF Combox Grid
<ComboBox DisplayMemberPath="Name" SelectedValuePath="Id" ItemsSource="{Binding}" Name="cobTeam" SelectionChanged="cobTeam_SelectionChanged" />
或者:
cobTeamName.Itemsource=dataTable.DefaultView;
cobTeamName.DisplayName="Name";
cobTeamName.SelectedValuePath="Id";
cobTeamName.SelectedValue="XX";
2.
<UserControl.Resources>
<ImageSource x:Key="delete">Images/delete.gif</ImageSource>
<ImageSource x:Key="edit">Images/edit.gif</ImageSource>
<ImageSource x:Key="view">Images/view.gif</ImageSource>
</UserControl.Resources>
<DataGrid AutoGenerateColumns="False" Name="gridPlanFlow" ItemsSource="{Binding}" CanUserAddRows="False" Background="{x:Null}">
<DataGrid.Columns>
<DataGridTextColumn Header="序号" Binding="{Binding OrderNo}" Width="80"/>
<DataGridTextColumn Header="预案" Binding="{Binding PlanTitle}" Width="100"/>
<DataGridTextColumn Header="内容" Binding="{Binding Content}" Width="100"/>
<DataGridTextColumn Header="附件" Binding="{Binding Attachment}" Width="140"/>
<DataGridTextColumn Header="技术组" Binding="{Binding TeamName}" Width="140"/>
<DataGridTextColumn Header="指派人" Binding="{Binding AssignerName}" Width="140"/>
//Grid中插入图片作为信息
<DataGridTemplateColumn Header="浏览" >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Image Name="imgPlanFlowView" Tag="{Binding OrderNo}" Source="{StaticResource view}"
MouseLeftButtonDown="imgPlanFlowView_MouseLeftButtonDown"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="编辑" >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Image Name="imgPlanFlowEdit" Tag="{Binding OrderNo}" Source="{StaticResource edit}"
MouseLeftButtonDown="imgPlanFlowEdit_MouseLeftButtonDown"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="删除">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Image Name="imgPlanFlowDelete" Tag="{Binding OrderNo}" Source="{StaticResource delete}"
MouseLeftButtonDown="imgPlanFlowDelete_MouseLeftButtonDown"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
/// <summary>
/// 加载预案流程
/// </summary>
private void RefreshPlanFlow()
{
DBAccess.BLL.planflow bll = new DBAccess.BLL.planflow();
DataTable dt = (bll.GetList("1=1")).Tables[0];
CacheAttachmentOrPlan();
//如果数据库中的字段 不能直接显示在Grid中,则需要添加DataTable的列,进行组合,然后再重新绑定此列
dt.Columns.Add("PlanTitle", typeof(string));
dt.Columns.Add("Attachment", typeof(string));
dt.Columns.Add("TeamName", typeof(string));
dt.Columns.Add("AssignerName", typeof(string));
foreach (DataRow dr in dt.Rows)
{
if (!string.IsNullOrEmpty(dr["PlanId"].ToString()))
{
dr["PlanTitle"] = DicPlanList[dr["PlanId"].ToString()];
}
if (!string.IsNullOrEmpty(dr["AttachmentId"].ToString()))
{
dr["Attachment"] = DicAttachment[dr["AttachmentId"].ToString()];
}
if (!string.IsNullOrEmpty(dr["TeamId"].ToString()))
{
dr["TeamName"] = DicTeamList[dr["TeamId"].ToString()];
}
if (!string.IsNullOrEmpty(dr["AssignerId"].ToString()))
{
dr["AssignerName"] = DicEmployeeList[dr["AssignerId"].ToString()];
}
}
gridPlanFlow.DataContext = dt;
}
4.DataTable 针对某列排序
方法一: datatable.Compute("max(列名)", "")
方法二:
DataRow[] drow = dtPue.Select("", "列名 asc");
//DataRow[] drow = dtPue.Select("", "列名 desc");
if (drow.Length > 0)
{
double min = double.Parse(drow[0]["列名"].ToString());
double max = double.Parse(drow[drow.Length - 1]["列名"].ToString());
}