Advertisement
Dazzer1966

Combobox Filter

Jul 2nd, 2022 (edited)
1,159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.54 KB | None | 0 0
  1.  #region class List Combo test
  2.         void fillTestGrid()//Fills grid with all categories
  3.         {
  4.             List<Screwfix> scr = sc.GetAllScrewfixResults();
  5.             dgvTest.DataSource = scr;
  6.         }
  7.  
  8.         void cbx1Test()//Fills combo1 with CategoryA
  9.         {
  10.             List<Screwfix> scr = sc.GetAllScrewfixResults();
  11.             this.comboBox1.DataSource = scr.Select(s => s.CategoryA).Distinct().ToList();
  12.             comboBox1.Text = "-Select-";
  13.         }
  14.         void cbx2Test()//Fills combo2 with CategoryB...not used in this example
  15.         {
  16.             List<Screwfix> scr = sc.GetAllScrewfixResults();
  17.             this.comboBox2.DataSource = scr.Select(s => s.CategoryB).Distinct().ToList();
  18.             comboBox2.Text = "-Select-";
  19.         }
  20.  
  21.         private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
  22.         {
  23.             List<Screwfix> scr = sc.GetAllScrewfixResults();
  24.             dgvTest.DataSource = scr.Where(x => x.CategoryA.Contains(comboBox1.Text)).ToList();
  25.  
  26.             if (comboBox1.Text == "Brackets")//CategoryA
  27.             {
  28.                 comboBox2.Items.Clear();
  29.                 comboBox2.Text = "-Select-";
  30.                 comboBox2.Items.Add("Plates");//CatB
  31.                 comboBox2.Items.Add("Angled brackets");//CatB
  32.                 return;
  33.             }
  34.             else
  35.             if (comboBox1.Text == "Plumbing")//CatA
  36.             {
  37.                 comboBox2.Items.Clear();
  38.                 comboBox2.Text = "-Select-";
  39.                 comboBox2.Items.Add("Copper fittings");//CatB
  40.                 comboBox2.Items.Add("Fittings");
  41.                 comboBox2.Items.Add("Hoses and fittings");
  42.                 comboBox2.Items.Add("Soldering");
  43.                 comboBox2.Items.Add("Waste accessories");
  44.                 comboBox2.Items.Add("Waste pipe and fittings");
  45.                 comboBox2.Items.Add("Water pipe");
  46.                 return;
  47.             }
  48.             //comboBox2.Enabled = true;
  49.         }
  50.         private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
  51.         {
  52.             List<Screwfix> scr = sc.GetAllScrewfixResults();
  53.             dgvTest.DataSource = scr.Where(x => x.CategoryB.Contains(comboBox2.Text)).ToList();
  54.         }
  55.  
  56.         private void txtTest_TextChanged(object sender, EventArgs e)//Works as expected
  57.         {
  58.             List<Screwfix> scr = sc.GetAllScrewfixResults();
  59.             dgvTest.DataSource = scr.Where(s => s.Description.ToLower().Contains(txtTest.Text.ToLower())).ToList();
  60.         }
  61.         #endregion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement