2013-04-20 91 views
0

我正在开发WPF中的应用程序,并且该应用程序的一部分涉及提取和合并数据frfom三个excel工作表并显示在datagrid中。现在,如果datagrid中的一行具有与多个应用程序相对应的队列,则它将显示一个组合框,通过在该Excel工作表中查找相应的队列名称,该组合框的项目将从另一个Excel表中拉出。在WPF中动态添加组合框在Datagrid细胞中

我以前使用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相同的功能。请帮助我。

回答