How can I create an active filtering on an DataGridView?
-
Hello eveyone, I have a DataGridView which holds columns such as (FirstName, LastName Email, HomeAddress). I would like to create a filter which filter the data base on the LastName. I would like the filtering happens as soon as the user starts to type in the first text letter in an designated area used for filtering the data. Let's say, once the user types the first letter "K" a list of last names starting with "K" appears. once the user types the second letter "h" the filter result display the lastname starting with "kh" and so on. I am not even sure what this functionality is called! I just called it "Active Filtering". I was thinking of having a comboBox for the typing area and displaying the result of filtering. I am not sure if this is the right approach. Can someone be kind enough to tell me how I can get this done and what is the right approach for this. Is the any particulare Controller than I can use for this. Any information would be appriciated. Thank you very much and have a great day. Khoramdin
-
Hello eveyone, I have a DataGridView which holds columns such as (FirstName, LastName Email, HomeAddress). I would like to create a filter which filter the data base on the LastName. I would like the filtering happens as soon as the user starts to type in the first text letter in an designated area used for filtering the data. Let's say, once the user types the first letter "K" a list of last names starting with "K" appears. once the user types the second letter "h" the filter result display the lastname starting with "kh" and so on. I am not even sure what this functionality is called! I just called it "Active Filtering". I was thinking of having a comboBox for the typing area and displaying the result of filtering. I am not sure if this is the right approach. Can someone be kind enough to tell me how I can get this done and what is the right approach for this. Is the any particulare Controller than I can use for this. Any information would be appriciated. Thank you very much and have a great day. Khoramdin
//load data in DataTable or DataSet private void LoadData() {
this.sqlDataAdapter1.Fill(this.ds_ordres1.Tables["orders"]); this.dataGridView1.DataSource = this.ds_ordres1.Tables["orders"].DefaultView;
} In TextBox_Changed event handler of Your Search TextBox, write This Code : private void textBox1_TextChanged(object sender, EventArgs e) { //in this example, row filter set on customerIDthis.ds_ordres1.Tables["orders"].DefaultView.RowFilter = "customerID like '" + this.textBox1.Text + "%'";
} -
Hello eveyone, I have a DataGridView which holds columns such as (FirstName, LastName Email, HomeAddress). I would like to create a filter which filter the data base on the LastName. I would like the filtering happens as soon as the user starts to type in the first text letter in an designated area used for filtering the data. Let's say, once the user types the first letter "K" a list of last names starting with "K" appears. once the user types the second letter "h" the filter result display the lastname starting with "kh" and so on. I am not even sure what this functionality is called! I just called it "Active Filtering". I was thinking of having a comboBox for the typing area and displaying the result of filtering. I am not sure if this is the right approach. Can someone be kind enough to tell me how I can get this done and what is the right approach for this. Is the any particulare Controller than I can use for this. Any information would be appriciated. Thank you very much and have a great day. Khoramdin
The reply posted by hdv212 is correct. You can also achieve the same by introducing a Binding Source. -------------- BindingSource myBindingSource = new BindingSource() private Form1_Load() { myBindingSource.DataSource = myDataSet; myBindingSource.DataMember = "myTableName"; // TableName on the myDataSet myBindingSource.Filter = ""; myGridView.DataSource = myBindingSource; } Now in your TextBox_Changed Event write the following code { myBindingSource.Filter = "lastName = " + textBox1.text; } :-O