Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Combobox and "autocompletion"

Combobox and "autocompletion"

Scheduled Pinned Locked Moved C#
wpfwcfregexjsonhelp
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    TMattC
    wrote on last edited by
    #1

    I have bound a BindingList<Produkt> to a ComboBox. When the user writes some text into the combobox, it will remove (filter out) all the entries that doesnt match what the user has entered, and then open the list showing the rest for the user to select one. The idea is that the more the user writes, the fewer options will be listed. The binding and filtering part works fine, but the problem is that when the user writes the first letter, the list opens up and autocompletes (in the text field) with the first entry of the list. Is there a way to turn this auto-completion off? I want the user to have the opportunity to keep writing OR to actively select an entry from the list.

        public void Init(BindingList \_produktLst)
        {
            produktLst = \_produktLst;
            namnCbx.DataSource = produktLst;
            namnCbx.DisplayMember = "Namn";
            namnCbx.ValueMember = "Namn";
        }
    
        private void namnCbx\_TextChanged(object sender, EventArgs e)
        {
            RunFilter();
        }
    
        private void RunFilter()
        {
            BindingList filteredLst;
    
            if (namnCbx.Text.Length == 0) // Om fältet är tomt
            {
                namnCbx.DataSource = produktLst;
            }
            else // Om det finns kriterier att filtrera på
            {
                filteredLst = new BindingList(produktLst.Where(delegate(Produkt p)
                    {
                        if (!p.Namn.Contains(namnCbx.Text))
                            return false;
                        else
                            return true;
                    }
                ).ToList());
    
                namnCbx.DataSource = filteredLst;
                if(namnCbx.Focused)
                    namnCbx.DroppedDown = true;
            }
        }
        }
    
    T S 2 Replies Last reply
    0
    • T TMattC

      I have bound a BindingList<Produkt> to a ComboBox. When the user writes some text into the combobox, it will remove (filter out) all the entries that doesnt match what the user has entered, and then open the list showing the rest for the user to select one. The idea is that the more the user writes, the fewer options will be listed. The binding and filtering part works fine, but the problem is that when the user writes the first letter, the list opens up and autocompletes (in the text field) with the first entry of the list. Is there a way to turn this auto-completion off? I want the user to have the opportunity to keep writing OR to actively select an entry from the list.

          public void Init(BindingList \_produktLst)
          {
              produktLst = \_produktLst;
              namnCbx.DataSource = produktLst;
              namnCbx.DisplayMember = "Namn";
              namnCbx.ValueMember = "Namn";
          }
      
          private void namnCbx\_TextChanged(object sender, EventArgs e)
          {
              RunFilter();
          }
      
          private void RunFilter()
          {
              BindingList filteredLst;
      
              if (namnCbx.Text.Length == 0) // Om fältet är tomt
              {
                  namnCbx.DataSource = produktLst;
              }
              else // Om det finns kriterier att filtrera på
              {
                  filteredLst = new BindingList(produktLst.Where(delegate(Produkt p)
                      {
                          if (!p.Namn.Contains(namnCbx.Text))
                              return false;
                          else
                              return true;
                      }
                  ).ToList());
      
                  namnCbx.DataSource = filteredLst;
                  if(namnCbx.Focused)
                      namnCbx.DroppedDown = true;
              }
          }
          }
      
      T Offline
      T Offline
      TMattC
      wrote on last edited by
      #2

      I think this question might boil down to: Can you open the list of a combobox without having one of the list entries selected, ie having something entirely different in the input field?

      1 Reply Last reply
      0
      • T TMattC

        I have bound a BindingList<Produkt> to a ComboBox. When the user writes some text into the combobox, it will remove (filter out) all the entries that doesnt match what the user has entered, and then open the list showing the rest for the user to select one. The idea is that the more the user writes, the fewer options will be listed. The binding and filtering part works fine, but the problem is that when the user writes the first letter, the list opens up and autocompletes (in the text field) with the first entry of the list. Is there a way to turn this auto-completion off? I want the user to have the opportunity to keep writing OR to actively select an entry from the list.

            public void Init(BindingList \_produktLst)
            {
                produktLst = \_produktLst;
                namnCbx.DataSource = produktLst;
                namnCbx.DisplayMember = "Namn";
                namnCbx.ValueMember = "Namn";
            }
        
            private void namnCbx\_TextChanged(object sender, EventArgs e)
            {
                RunFilter();
            }
        
            private void RunFilter()
            {
                BindingList filteredLst;
        
                if (namnCbx.Text.Length == 0) // Om fältet är tomt
                {
                    namnCbx.DataSource = produktLst;
                }
                else // Om det finns kriterier att filtrera på
                {
                    filteredLst = new BindingList(produktLst.Where(delegate(Produkt p)
                        {
                            if (!p.Namn.Contains(namnCbx.Text))
                                return false;
                            else
                                return true;
                        }
                    ).ToList());
        
                    namnCbx.DataSource = filteredLst;
                    if(namnCbx.Focused)
                        namnCbx.DroppedDown = true;
                }
            }
            }
        
        S Offline
        S Offline
        Simon_Whale
        wrote on last edited by
        #3

        Have you thought about using the AutoComplete property on the combobox and set it to suggest?

        Every day, thousands of innocent plants are killed by vegetarians. Help end the violence EAT BACON

        T 1 Reply Last reply
        0
        • S Simon_Whale

          Have you thought about using the AutoComplete property on the combobox and set it to suggest?

          Every day, thousands of innocent plants are killed by vegetarians. Help end the violence EAT BACON

          T Offline
          T Offline
          TMattC
          wrote on last edited by
          #4

          Well, my idea was to not use any autocomplete, but I found this article Auto Complete ComboBox[^] where he is using it, and it works really well, just a slightly different approach. So five starts on that one. :-D

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups