Filtering data in datagridview using 2 combobox in c# with MS Access DB

Jamie Hayashi 121 Reputation points

Good day everyone, please help me this problem.
color green represent other combo box and also color blue.

I want to filter the data in datagridview with different combo box.

fill free to message me in my gmail account jamei432294@Stuff .com
Thank you so much.

Here my code in Room Type combobox.

        string query = "select * from CheckInRoom where RType = '" +cmbRtype.SelectedItem.ToString() +"'";  
        OleDbDataAdapter da = new OleDbDataAdapter(query, con);  
        OleDbCommandBuilder builder = new OleDbCommandBuilder(da);  
        var ds = new DataSet();  
        CheckIndataGridView1.DataSource = ds.Tables[0];  


An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,465 questions
Access Development
Access Development
Access: A family of Microsoft relational database management systems designed for ease of use.Development: The process of researching, productizing, and refining new or existing technologies.
841 questions
0 comments No comments
{count} votes

Accepted answer
  1. Karen Payne MVP 35,286 Reputation points

    The following works with any database as at the time used we are not connected to the database at all. You can see a Microsoft article on this code.

    The best way to filter is adding a BindingSource, set it's DataSource to ds.Tables[0] then use my language extension.

    public static void RowFilterTwoConditions(this BindingSource sender, string field1, string value1, string pField2, string value2, bool caseSensitive = false)
        sender.DataTable().CaseSensitive = caseSensitive;
        sender.DataView().RowFilter = $"{field1} = '{value1.EscapeApostrophe()}' AND {pField2} = '{value2.EscapeApostrophe()}'";

    Lets call the BindingSource _bindingSource

    public partial class Form1 : Form
        private readonly BindingSource _bindingSource = new BindingSource();

    Mocked up call to filter

        "Value from ComboBox", 
        "Value from smoking room ComboBox");

    Another extension to clear the filter

    public static void RowFilterClear(this BindingSource sender)
        sender.DataView().RowFilter = "";
    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful