【问题标题】:Adding Combobox in a Datagrid cell dynamically in WPF在 WPF 中动态地在 Datagrid 单元格中添加组合框
【发布时间】:2013-04-20 18:45:13
【问题描述】:

我正在 WPF 中开发一个应用程序,该应用程序的一部分涉及从三个 Excel 表中提取和合并数据并在数据网格中显示。现在,如果 datagrid 中的一行有一个对应于多个应用程序的队列,那么它将显示一个组合框,通过在该 excel 表中查找对应的队列名称,将从另一个 excel 表中提取其项目。

我之前在 ASP.NET 中使用过相同的功能,并且使用以下代码很容易实现:

    for (int i = 0; i < dt.Rows.Count; i++)
  {
    //Filling datatable dsq from excel sheet
    //dsq contains the data where it is found out how many applications are there for               
   //ith row in Gridview

     count[i] = dsq.Tables[0].Rows.Count;

     foreach (GridViewRow row in gvApplications.Rows)
     {

     // Transferring gridview rows to a datatable
     if (row.Cells[0].Text.Trim().Equals(dt.Rows[i][0].ToString().Trim()))
       {
    //Dropdownlist is added only when no. of applications for each queue , i.e. , 
    /count[i] is greater than 1 , else level control is added.

         if (count[i] > 1)
            {
               DropDownList drp = new DropDownList();
               drp.DataSource = dsq.Tables[0];
                drp.DataTextField = "Application Name";
                drp.DataValueField = "Application Name";
                drp.DataBind();
               row.Cells[7].Controls.Add(drp);
             }
          }
           else
          {
             Label l = new Label();
            l.Text = dsq.Tables[0].Rows[0][0].ToString().Trim();
             l.ID = "label" + row.RowIndex.ToString();
            row.Cells[7].Controls.Add(l);

           }

                        }

现在我想要 WPf 中的相同功能。请帮帮我。

【问题讨论】:

    标签: wpf datagrid


    【解决方案1】:

    你可以在里面使用DataGridTemplateColumn,你可以把ContentControlDataTemplateSelector放在一起。

    【讨论】:

      猜你喜欢
      • 2012-04-05
      • 1970-01-01
      • 2013-08-12
      • 2012-10-06
      • 1970-01-01
      • 2021-11-14
      • 1970-01-01
      • 2013-11-17
      • 2013-06-16
      相关资源
      最近更新 更多