Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8908641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:14:05+00:00 2026-06-15T03:14:05+00:00

I have a datagridview and 5 ComboBoxes and I am trying to filter the

  • 0

I have a datagridview and 5 ComboBoxes and I am trying to filter the grid’s rows with ComboBox’s text values. The grid is filled with stored procedure depends on some conditions in FormLoad event. Should I fill it again in the btn_filter click event?

Anyway this exception is catched at code below: cannot bind to datatable with no name.

here is the code for btn_filter:

    private void btnFilter_Click(object sender, EventArgs e)
    {
        String filterStr = "";

        if (cmbGrp.Text.Trim() != String.Empty)
            filterStr +=  "group ='" + cmbGrp.Text.Trim() + "' and";
        if(cmbMdl.Text.Trim() != String.Empty)
            filterStr += " model ='" + cmbMdl.Text.Trim() + "' and";
        if (cmbTrh.Text.Trim() != String.Empty)
            filterStr += " tarh ='" + cmbTrh.Text.Trim() + "' and";
        if (cmbSiz.Text.Trim() != String.Empty)
            filterStr += " size ='" + cmbSiz.Text.Trim() + "' and";
        if (cmbClr.Text.Trim() != String.Empty)
            filterStr += " color ='" + cmbClr.Text.Trim() + "'";            

        if (filterStr.LastIndexOf("and") == filterStr.Length - 3)
            filterStr = filterStr.Remove(filterStr.Length-3,3);


        DataView view = new DataView();
        if (condition1)
            view.Table = Production.usp1(txtProdCode.Text);
        else if (condition2)
            view.Table = Production.usp2();
        else
            return;
        view.RowFilter = filterStr;
        dgv.DataSource = view;    
    }

and here is the storedProcedure related functions (in Production class):

    public static DataTable usp2()
    {
        SqlCommand cmd = new SqlCommand("usp2");
        return callProc(cmd);
    }

    public static DataTable usp1(String prod_code)
    {
        SqlCommand cmd = new SqlCommand("usp1");
        cmd.Parameters.Add(new SqlParameter("@prod_code", prod_code));
        return callProc(cmd);
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T03:14:06+00:00Added an answer on June 15, 2026 at 3:14 am

    Try specify Name explicitly. use DataTable.TableName="Name" before you create your dataview.
    You btnFilter_Click method should look like this:

     private void btnFilter_Click(object sender, EventArgs e)
        {
            String filterStr = "";
    
            filterStr +=      "grp_name " + (cmbGrp.Text.Trim() == String.Empty ? " like '%'" : "='" + cmbGrp.Text.Trim()) + "'";
            filterStr += " and mdl_name " + (cmbMdl.Text.Trim() == String.Empty ? " like '%'" : "='" + cmbMdl.Text.Trim()) + "'";
            filterStr += " and trh_name " + (cmbTrh.Text.Trim() == String.Empty ? " like '%'" : "='" + cmbTrh.Text.Trim()) + "'";
            filterStr += " and siz_name " + (cmbSiz.Text.Trim() == String.Empty ? " like '%'" : "='" + cmbSiz.Text.Trim()) + "'";
            filterStr += " and clr_name " + (cmbClr.Text.Trim() == String.Empty ? " like '%'" : "='" + cmbClr.Text.Trim()) + "'";
    
            DataView view = new DataView();
    
            if (condition1)
               {
                var dt = Production.usp1(txtProdCode.Text);
                dt.TableName="usp1";
                view.Table = dt;
                }
            else if (condition2)
                {
                var dt = Production.usp2();
                dt.TableName="usp2";
                view.Table = dt;
                }
            else
                return;
            view.RowFilter = filterStr;
            dgv.DataSource = view;    
        }  
    

    To not reload grid with values from DB again you can cast your existing datasource to DataView like this:

    (dataGridViewFields.DataSource as DataTable).DefaultView.RowFilter  
    

    Read more in this question

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a datagridview filled with 8 columns of comboboxes, and 32 rows. private
I have DataGridView which contains two ComboBox columns. The second ComboBox will be filled
I have a datagridview and a combobox which get populated randomly with data. However,
I have datagridview with checkbox column, but I want, that some of the columns
Say I have a DataGridView in which I dynamically build up a ComboBox column
I have a DataGridView which has different rows and columns and it work perfectly
I have tables like that in Datagridview: Name Money ------------- Hi 100 //here Combobox
I have a datagridview with a bound combobox column which contains decimal value. There
I have a dataGridView with comboBox dropdowns for each cell. I would like to
I have a datagridview and I want to fill a combobox from one of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.