Click here to Skip to main content
15,311,717 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey,
I am fairly new to C# programming and now need help with the following problem.
On my form I have a DataGridView with 3 Comboboxes and a Textfield. The DataGridView is bound and populate of an access db table with Dataset and Boundingsource. This works well and I want to keep it that way. The Comboboxes are filled with a permanent collection from which to choose. The intention is now to filter the DataGridView on the first three columns with the Comboboxes. The filtering is always a combination of the three boxes together or alone. The more filters, the more the DataGridView is filtered. The purpose of the Textfield is to filter the DataGridView on any text and then execute this with the "Search" button. The "Search" only works with the Textfield. The "Clear" button is used to reset all the filters.
Thanks for the replies.

THis is my code so far

C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;


namespace Test
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'combobox_ExperimentDataSet.Tabel1' table. You can move, or remove it, as needed.
            this.tabel1TableAdapter.Fill(this.combobox_ExperimentDataSet.Tabel1);
        }

        private void _cmbSchool_SelectedIndexChanged(object sender, EventArgs e)
        {
            
        }

        private void _cmbCategorie1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void _cmbCategorie2_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void Search_Click(object sender, EventArgs e)
        {

        }

        private void Clear_Click(object sender, EventArgs e)
        {

        }
    }
}


What I have tried:

I am continuously searching about this and the answers i can find does not fit to what im looking for.
Posted
Updated 28-Nov-21 1:35am

1 solution

You have a binding source, all you need to do is set the BindingSource.Filter Property[^] appropriately:
C#
myBindingsource.Filter = "Column1 = 'Hello' AND Column2 = 'World'";
Exactly what you set it to will depend on exactly what you want to filter by - and that's something only you can know; you won't find it "ready made" to slot into your code anywhere, so you will have to build the filter string yourself as needed dependign on what the user has selected so far.
   
Comments
Dominique Moons 30-Nov-21 16:39pm
   
Thanks, I'll take a look at the BindingSource.Filter Property to see how to use it properly and configure it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900