如何通过组合框选择过滤datagridview [英] How to filter datagridview by combo box selection

查看:67
本文介绍了如何通过组合框选择过滤datagridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我正在制作一个使用Windows窗体的程序,我已经构建了一些代码,比如这个



1.在文本框中写一个网址网址然后点击开始按钮,DataGridViews中显示的匹配数据。



2.我有6个DataGridViews。在First DataGridView中,匹配数据显示(步骤1)

然后,其他5个DataGridviews将显示为类似级联引用First DataGridView的行`
值(webApplicationName)< br $>


代码如下



现在我要添加这个

1添加Combobox并添加一些条件,例如[Show all]和[See over 100GB DB]



2.如果我选择[查看超过100GB DB]选项,因为DataGridView只显示匹配的行。



3.这意味着,我想使用Combobox选择过滤Datagridview,数据源已经是



绑定,所以我想不要改变DataSource ....



我试图找到combobox和DataGridView,但通常是相关的DataGridView中的Combobox ....



我怎样才能获得第一个DataGridViews的值(webApplicationName)



请有人帮帮我..我什么都不知道...



谢谢



我尝试了什么:



Hello, I`m making a program using Windows forms and I already built some codes, like this

1. Write a site url in Text Box then click Start Button, matched data showed in DataGridViews.

2. I have a 6 DataGridViews. In First DataGridView, matched data showed(step 1)
and then, other 5 DataGridviews will showed like cascade refer First DataGridView`s row`s
value(webApplicationName)

code is below

And Now I want to add this
1. Add Combobox and Add some conditions, for example, [Show all] and [See Over 100GB DB]

2. If I choose [See Over 100GB DB] option, in that DataGridView showed only matched rows.

3. It means, I want to filter Datagridview using Combobox Selection and Datasource is already

binded, so I want to do not change DataSource....

I try to find combobox and DataGridView, but usually related on Combobox in DataGridView....

And how can I get get first DataGridViews`s value(webApplicationName)

Please somebody help me.. I don`t have any idea...

Thanks

What I have tried:

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;
            }

        }

推荐答案

我找到了方法。使用DataView



代码是这样的



I found the way. Using DataView

code is like this

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 >= 500000000", mtcbContentDBSearchCondition.SelectedItem.ToString());
                mgrdContentDatabase.DataSource = dvContentDatabase;
            }
        }


这篇关于如何通过组合框选择过滤datagridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆