2016-10-07 50 views
1

我真的做节目,我已经建立了一些代码,这样如何使用DataGridView的组合框不使用Windows窗体改变数据源

  1. 写文本框中输入网站网址,然后点击开始按钮来筛选,匹配数据显示在DataGridViews中。

  2. 我有一个6 DataGridViews。在首先的DataGridView,匹配的数据显示(步骤1) ,然后,其他5个DataGridviews将显示像级联指首先的DataGridView row`s值(webApplicationName)

代码如下

private void mtbtnStart_Click(object sender, EventArgs e) 
    { 
     string webApplicationName = string.Empty; 
     string siteID = string.Empty; 
     mtlblError.Text = "No record returned."; 

     Migration_Status_DAC dac = new Migration_Status_DAC(); 
     DataSet ds = new DataSet(); 

     //Web Application   
     ds = dac.SelectWebApplicationStatus(mtextUrl.Text); 
     DataTable dt = ds.Tables[0]; 


     if (ds != null && dt != null && dt.Rows.Count > 0) 
     { 
      webApplicationName = dt.Rows[0]["AppName"].ToString(); 
      mgrdWebApplication.DataSource = dt; 

      //Content Database 
      ds = dac.SelectContentDatabaseStatus(webApplicationName); 
      DataTable dtContent = ds.Tables[0]; 
      if (ds != null && dtContent != null && dtContent.Rows.Count > 0) 
      { 
       mtlblError.Visible = false; 
       mgrdContentDatabase.DataSource = dtContent; 

       //SiteCollection 
       ds = dac.SelectSiteCollectionStatus(webApplicationName); 
       DataTable dtSiteCol = ds.Tables[0]; 
       if (ds != null && dtSiteCol != null && dtSiteCol.Rows.Count > 0) 
       { 
        mgrdSiteCollections.DataSource = dtSiteCol; 

        //Sites 
        ds = dac.SelectSitesStatus(webApplicationName); 
        DataTable dtSites = ds.Tables[0]; 
        if (ds != null && dtSites != null && dtSites.Rows.Count > 0) 
        { 
         siteID = dtSites.Rows[0]["SiteID"].ToString(); 
         mgrdSites.DataSource = dtSites; 

         //Lists 
         ds = dac.SelectListsStatus(siteID); 
         DataTable dtLists = ds.Tables[0]; 
         if (ds != null && dtLists != null && dtLists.Rows.Count > 0) 
         { 
          mgrdLists.DataSource = dtLists; 
         } 
         //Document Library 
         ds = dac.SelectDocumentLibraryStatus(siteID); 
         DataTable dtDocLib = ds.Tables[0]; 
         if (ds != null && dtDocLib != null && dtDocLib.Rows.Count > 0) 
         { 
          mgridDocumentLibrary.DataSource = dtDocLib; 
         } 
        } 
        else 
        { 
         mtlblError.Visible = true; 
        } 
       } 
       else 
       { 
        mtlblError.Visible = true; 
       } 
      } 
      else 
      { 
       mtlblError.Visible = true; 
      } 

     } 
     else 
     { 
      mgrdWebApplication.DataSource = null; 
      mgrdContentDatabase.DataSource = null; 
      mgrdSiteCollections.DataSource = null; 
      mgrdSites.DataSource = null; 
      mgrdLists.DataSource = null; 
      mgridDocumentLibrary.DataSource = null; 
     } 

    } 

而现在,我想添加这个

  1. 添加组合框,并添加一些条件,例如,[查看全部]和[见超过100GB DB]

  2. 如果我选择[查看超过100GB的数据库]选项,则DataGridView只显示匹配的行。

  3. 这意味着,我想用组合框选择过滤的DataGridView和数据源已经

    绑定,所以我想不改变数据源....

我试图找到组合框和DataGridView的,但通常与对组合框在DataGridView中....

和我如何能得到获得第一DataGridViews`s值(webApplicationName)

请有人帮助我。我不有任何想法...

感谢

+0

可能重复o f [过滤DataGrid动态名称与TextBox](http://stackoverflow.com/questions/34221657/filter-datagrid-for-name-with-textbox-dynamically) –

回答

2

您可以使用BindingSource的数据源的绑定到你的DataGridView。 这样,您只需更改bindingSource的Filter属性,并且筛选器将自动应用于网格中显示的数据。 无需更改数据源。

+0

谢谢你的回复Hassan Eskandari。 –

+0

但我用Dataview RowFilter lkie这个 –

+0

dvLists.RowFilter = string.Format(“ListLastModifyDate <= listModifiedDate”,mtCbListsSearchConditions.SelectedItem。的ToString()); a –

0

我建了一个代码,并且效果很好

  1. 使用组合框SelectedItemChanged事件

  2. 使用数据视图和DataView.RowFilter

代码如下

 private void mtcbContentDBSearchCondition_SelectedIndexChanged(object sender, EventArgs e) 
     { 
      DataView dvContentDatabase = new DataView(dtContent); 

      if (mtcbContentDBSearchCondition.SelectedItem.ToString() == "All") 
      { 
       mgrdContentDatabase.DataSource = dtContent; 
      } 
      else 
      { 
       dvContentDatabase.RowFilter = string.Format("ContentDBSize >= 300000000", mtcbContentDBSearchCondition.SelectedItem.ToString()); 
       mgrdContentDatabase.DataSource = dvContentDatabase; 
      } 
     } 
相关问题