Incremental Search

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Christopher Weaver

    Incremental Search

    What's the best way to go about an incremental search within a ComboBox?
    I've looked at the FindString method, but before I go down that road, I'm
    wondering if there's a component out there that would serve the same purpose
    more easily.


  • Bruce Wood

    #2
    Re: Incremental Search

    Do you mean autocompletion, where you move down the combo box as the
    user types successive characters until they find the correct entry?

    Search this newsgroup for "combobox" and "autocomple te". You should
    find pointers to some implementations .

    Comment

    • Christopher Weaver

      #3
      Re: Incremental Search

      "autocompletion " is another way of puting it, yes. I've just finished
      downloading over 9,000 messages from this newsgroup and couldn't find a
      single one that contained combobox and autocomplete. Seemed like a good
      idea to me too.


      "Bruce Wood" <brucewood@cana da.com> wrote in message
      news:1127625464 .445045.237100@ f14g2000cwb.goo glegroups.com.. .[color=blue]
      > Do you mean autocompletion, where you move down the combo box as the
      > user types successive characters until they find the correct entry?
      >
      > Search this newsgroup for "combobox" and "autocomple te". You should
      > find pointers to some implementations .
      >[/color]


      Comment

      • Bruce Wood

        #4
        Re: Incremental Search

        I'm using Google Groups Beta, and searching on "combobox autocomplete"
        gets me 18 hits. You'll probably get even more in
        microsoft.publi c.dotnet.framew ork.windowsform s and
        microsoft.publi c.dotnet.framew ork.windowsform s.controls.

        Comment

        • Christopher Weaver

          #5
          Re: Incremental Search

          I didn't find any.

          But perhaps some out there would know how to iterate the list within a
          ComboBox. I'm having trouble referencing it.


          Comment

          • Bruce Wood

            #6
            Re: Incremental Search

            Here is a post by Jeffrey Tan, from one of the other newsgroups:

            I am not sure of your meaning of "searchable combobox", can you show us

            more information of your request? If you want to implement a
            AutoComplete
            combobox, you may refer to the 2 articles below:
            "AutoComple te ComboBox in VB.Net"

            "ComboBox with AutoComplete 1.1"



            Also, based on my knowledge, in .Net 2.0, Whidbey will introduce a new
            AutoComplete feature for the build-in combobox control.
            =============== =============== =============== ==========
            Thank you for your patience and cooperation. If you have any questions
            or
            concerns, please feel free to post it in the group. I am standing by to
            be
            of assistance.


            Best regards,
            Jeffrey Tan
            Microsoft Online Partner Support
            Get Secure! - www.microsoft.com/security
            This posting is provided "as is" with no warranties and confers no
            rights.

            Comment

            • Christopher Weaver

              #7
              Re: Incremental Search

              This looks like what I'm looking for. I will study it and let you know if I
              have more questions.

              Thanks


              "Bruce Wood" <brucewood@cana da.com> wrote in message
              news:1128118083 .360679.196130@ z14g2000cwz.goo glegroups.com.. .[color=blue]
              > Here is a post by Jeffrey Tan, from one of the other newsgroups:
              >
              > I am not sure of your meaning of "searchable combobox", can you show us
              >
              > more information of your request? If you want to implement a
              > AutoComplete
              > combobox, you may refer to the 2 articles below:
              > "AutoComple te ComboBox in VB.Net"
              > http://www.codeproject.com/vb/net/au...e_combobox.asp
              > "ComboBox with AutoComplete 1.1"
              > http://www.csharphelp.com/archives3/archive502.html
              >
              >
              > Also, based on my knowledge, in .Net 2.0, Whidbey will introduce a new
              > AutoComplete feature for the build-in combobox control.
              > =============== =============== =============== ==========
              > Thank you for your patience and cooperation. If you have any questions
              > or
              > concerns, please feel free to post it in the group. I am standing by to
              > be
              > of assistance.
              >
              >
              > Best regards,
              > Jeffrey Tan
              > Microsoft Online Partner Support
              > Get Secure! - www.microsoft.com/security
              > This posting is provided "as is" with no warranties and confers no
              > rights.
              >[/color]


              Comment

              • Christopher Weaver

                #8
                Re: Incremental Search

                I've just looked over the first example you referred me to and find that it
                uses ComboBox.FindSt ring. I didn't know such a thing existed! Don't know
                how I missed it.


                Thanks.

                "Bruce Wood" <brucewood@cana da.com> wrote in message
                news:1128118083 .360679.196130@ z14g2000cwz.goo glegroups.com.. .[color=blue]
                > Here is a post by Jeffrey Tan, from one of the other newsgroups:
                >
                > I am not sure of your meaning of "searchable combobox", can you show us
                >
                > more information of your request? If you want to implement a
                > AutoComplete
                > combobox, you may refer to the 2 articles below:
                > "AutoComple te ComboBox in VB.Net"
                > http://www.codeproject.com/vb/net/au...e_combobox.asp
                > "ComboBox with AutoComplete 1.1"
                > http://www.csharphelp.com/archives3/archive502.html
                >
                >
                > Also, based on my knowledge, in .Net 2.0, Whidbey will introduce a new
                > AutoComplete feature for the build-in combobox control.
                > =============== =============== =============== ==========
                > Thank you for your patience and cooperation. If you have any questions
                > or
                > concerns, please feel free to post it in the group. I am standing by to
                > be
                > of assistance.
                >
                >
                > Best regards,
                > Jeffrey Tan
                > Microsoft Online Partner Support
                > Get Secure! - www.microsoft.com/security
                > This posting is provided "as is" with no warranties and confers no
                > rights.
                >[/color]


                Comment

                • Christopher Weaver

                  #9
                  Re: Incremental Search

                  Hang on! I spoke to soon. This doesn't answer my problem completely.

                  I'm still having trouble with the ComboBox internal behavior that causes it
                  to move to the first item it can find in which the first character matches
                  the character last typed. The displayed item jumps as the ComboBox moves to
                  the item that it has selected then on to the one that my code selects. Is
                  there any way around this?



                  "Bruce Wood" <brucewood@cana da.com> wrote in message
                  news:1128118083 .360679.196130@ z14g2000cwz.goo glegroups.com.. .[color=blue]
                  > Here is a post by Jeffrey Tan, from one of the other newsgroups:
                  >
                  > I am not sure of your meaning of "searchable combobox", can you show us
                  >
                  > more information of your request? If you want to implement a
                  > AutoComplete
                  > combobox, you may refer to the 2 articles below:
                  > "AutoComple te ComboBox in VB.Net"
                  > http://www.codeproject.com/vb/net/au...e_combobox.asp
                  > "ComboBox with AutoComplete 1.1"
                  > http://www.csharphelp.com/archives3/archive502.html
                  >
                  >
                  > Also, based on my knowledge, in .Net 2.0, Whidbey will introduce a new
                  > AutoComplete feature for the build-in combobox control.
                  > =============== =============== =============== ==========
                  > Thank you for your patience and cooperation. If you have any questions
                  > or
                  > concerns, please feel free to post it in the group. I am standing by to
                  > be
                  > of assistance.
                  >
                  >
                  > Best regards,
                  > Jeffrey Tan
                  > Microsoft Online Partner Support
                  > Get Secure! - www.microsoft.com/security
                  > This posting is provided "as is" with no warranties and confers no
                  > rights.
                  >[/color]


                  Comment

                  • Bruce Wood

                    #10
                    Re: Incremental Search

                    I can't seem to visualize your problem... can you explain what's
                    happening in more detail?

                    Comment

                    • Christopher Weaver

                      #11
                      Re: Incremental Search

                      I've tried this with a DropDownStyle set to DropDown and DropDownList.

                      DropDown works well in that I'm able to use the SelectionStart and
                      SelectionLength properties to show the user which characters have been
                      acknowledged. Unfortunately, there is a visible jitter to the search
                      process. It appears that the component is implementing its default
                      behavior, which is to find the first item that begins with the character
                      just entered. It also appears as thought the highlighting of the selected
                      text is being removed and replaced with each key.

                      Also, if the user types too fast, characters are skipped in the search
                      process. I've tried implementing the solution to this expressed on the site
                      that you referenced in one of your earlier posts
                      (http://www.codeproject.com/vb/net/au...e_combobox.asp)
                      but it did not solve the problem.

                      All of the following processing takes place in KeyUp. I've omitted the code
                      that handles the backspace and excape keys.

                      private void cbTaskLookUp_Ke yUp(object sender,
                      System.Windows. Forms.KeyEventA rgs e)
                      {
                      string cbText = cbTaskLookUp.Te xt.ToUpper();
                      string cbItemText;
                      int cbTLUL = cbTaskLookUpInp ut.Length;
                      ComboBox cb = (ComboBox)sende r;
                      try
                      {
                      if ((e.KeyValue < 65 || e.KeyValue > 90) & e.KeyValue != 32)//other keys
                      are handled elsewhere
                      return;
                      cbTaskLookUpInp ut += (char)e.KeyValu e;
                      lblSoFar.Text = cbTaskLookUpInp ut;//for debugging
                      cbTLUL = cbTaskLookUpInp ut.Length;
                      LocateCBOItem(c b, cbTaskLookUpInp ut, cbTLUL);
                      }

                      finally
                      {
                      e.Handled = true;
                      }
                      }

                      private void LocateCBOItem(C omboBox cb, string InputString, int isLength)
                      {
                      int iFindString;
                      iFindString = cb.FindString(I nputString);
                      cb.SelectedInde x = iFindString;
                      cb.SelectionSta rt = 0;
                      cb.SelectionLen gth = isLength;
                      lblSoFar.Text += " " + iFindString.ToS tring();//for debugging
                      }

                      Thanks for your help.




                      "Bruce Wood" <brucewood@cana da.com> wrote in message
                      news:1128372185 .166077.211320@ g44g2000cwa.goo glegroups.com.. .[color=blue]
                      >I can't seem to visualize your problem... can you explain what's
                      > happening in more detail?
                      >[/color]


                      Comment

                      • Bruce Wood

                        #12
                        Re: Incremental Search

                        I think I see the problem.

                        The first link, the vb.net one, inexplicably implements the search
                        functionality as an event handler that can be attached to any combo
                        box. While this is nice and general, the event handler code runs _in
                        addition to_ any other code that would run as a part of a KeyUp event.
                        In particular, the combo box's normal KeyPress event code runs, then
                        your KeyUp event handler gets called. That's what is causing the
                        behaviour you're seeing.

                        I like the csharphelp version much better (the other link:
                        http://www.csharphelp.com/archives3/archive502.html ). It implements a
                        special kind of ComboBox by inheriting from ComboBox and _overriding_
                        KeyPress. This will have the effect of _replacing_ the normal ComboBox
                        KeyPress behaviour, which is more likely what you want.

                        By the way, .NET 2.0, which is due out next month, will include an
                        autocomplete feature for combo boxes built into the Framework, if you
                        can wait a month... :)

                        Comment

                        • Christopher Weaver

                          #13
                          Re: Incremental Search

                          I checked out the component. This is what I was looking for. It doesn't do
                          everything I wanted it to do, but I can fix that. I see now how to override
                          an event handler. I downloaded it and installed the DLL assembly in my
                          toolbar. I also changed one of the ComboBoxes on my form to the ACComboBox
                          class. Unfortunately, even though it compiled and ran, after I shut it
                          down, almost everything on the form that was not inherrited from the
                          superclass was gone. I was using a TabControl with four pages. The
                          TabControl is gone and most of the code associated with it is gone.

                          Do you have any idea what would cause this or how to recover the previous
                          version of the form?


                          "Bruce Wood" <brucewood@cana da.com> wrote in message
                          news:1128383563 .044644.195840@ z14g2000cwz.goo glegroups.com.. .[color=blue]
                          >I think I see the problem.
                          >
                          > The first link, the vb.net one, inexplicably implements the search
                          > functionality as an event handler that can be attached to any combo
                          > box. While this is nice and general, the event handler code runs _in
                          > addition to_ any other code that would run as a part of a KeyUp event.
                          > In particular, the combo box's normal KeyPress event code runs, then
                          > your KeyUp event handler gets called. That's what is causing the
                          > behaviour you're seeing.
                          >
                          > I like the csharphelp version much better (the other link:
                          > http://www.csharphelp.com/archives3/archive502.html ). It implements a
                          > special kind of ComboBox by inheriting from ComboBox and _overriding_
                          > KeyPress. This will have the effect of _replacing_ the normal ComboBox
                          > KeyPress behaviour, which is more likely what you want.
                          >
                          > By the way, .NET 2.0, which is due out next month, will include an
                          > autocomplete feature for combo boxes built into the Framework, if you
                          > can wait a month... :)
                          >[/color]


                          Comment

                          • Bruce Wood

                            #14
                            Re: Incremental Search

                            I've had this happen before. It happens when there's "something wrong"
                            with the code inside the "Windows Form Designer" generated section of
                            code, which is why they till you never to touch that.

                            In particular, I get this effect when I make a mistake in the
                            constructors of one of my derived controls (like the special-purpose
                            combo box), so the Designer can't create one, or an error in one of the
                            properties that the Designer is trying to read.

                            No, there's no way to get the code back, unless you have a version
                            control system. Debugging custom control is a pain. If you don't have
                            source code control, keep a back-up copy of your form somewhere.

                            Comment

                            • Christopher Weaver

                              #15
                              Re: Incremental Search

                              Alright. Looks like I need hourly backups or a version control system.

                              Back to the component itself. It needs a little work, especially in the UI;
                              if the ComboBox isn't wide enough to display all of itscontents, the user
                              can't see what's happening because it defaults to showing the right side
                              instead of the left. Also, it doesn't stay in the dropdown mode as the user
                              is typing in, so even if the dropdown list is wide enough the user is still
                              lost.

                              I'm thinking that it may not be worth the trouble to fix it up if there's a
                              better version coming out in another month. But then on the other hand, I
                              need addtional functionality -- like 'fetch another batch of records if you
                              can't find what you're looking for here' -- so I might work with this
                              version anyway.

                              Thanks for the tip.


                              "Bruce Wood" <brucewood@cana da.com> wrote in message
                              news:1128452872 .325801.63870@g 14g2000cwa.goog legroups.com...[color=blue]
                              > I've had this happen before. It happens when there's "something wrong"
                              > with the code inside the "Windows Form Designer" generated section of
                              > code, which is why they till you never to touch that.
                              >
                              > In particular, I get this effect when I make a mistake in the
                              > constructors of one of my derived controls (like the special-purpose
                              > combo box), so the Designer can't create one, or an error in one of the
                              > properties that the Designer is trying to read.
                              >
                              > No, there's no way to get the code back, unless you have a version
                              > control system. Debugging custom control is a pain. If you don't have
                              > source code control, keep a back-up copy of your form somewhere.
                              >[/color]


                              Comment

                              Working...