title: How can I prevent auto-select in ComboBox on drop-down except for exact matches?
body: <p>I have a ComboBox that is part of a detail display related to a data grid containing rows from a database.  No binding to the ComboBox exists, I am doing this manually.  The ComboBox allows manual entry, as if it were a text field, while still providing a drop-down of choices.</p>
  
  <p>My issue is that if I have manually entered text in the field, and the drop-down is clicked, the ComboBox apparently wants to seek out a match.  Also, it appears that the search is simple, so <code>KG</code> matches <code>KG/Day</code>.  I must avoid this and force an exact match.</p>
  
  <p>But further, I think I need to be able to govern the entire process myself, because to further complicate the matter, the drop-down item would actually read <code>KG/Day - kilograms/day</code>.  The database field from which the data is fetched, however, is only storing the portion prior to the hyphen, so <code>KG/Day</code>.</p>
  
  <p>So, I need to intercept the drop-down action in a way that allows me to do two things:</p>
  
  <p>1) Perform my own search to find whether or not I have ad-hoc text, or a "real" match.  As  in that it was originally selected from the drop-down; in other words, that I have <code>KG/Day</code> and not just <code>KG</code>.</p>
  
  <p>2) Eliminate the auto-search behavior that ComboBox wants to do.</p>
  
  <p>I have tried getting in front of these things using method handlers in the Form, such as </p>
  
  <blockquote>
    <p>ComboBox::DropDown() and ComboBox::DropDownClosed(),</p>
  </blockquote>
  
  <p>but it seems these still don't allow me to stop the basic ComboBox searching/matching.</p>
  
  <p>I have also tried creating a class of my own inherited from ComboBox, but I don't really know what to override, or in general how to go about getting what I want, stopping what I don't.</p>
  
  <p>So, with that, I thank you for your advice.</p>
  
  <p>EDIT:  to expand on what I tried already...
  In my inherited class, I was attempting to use a <code>WndProc</code> override.  Based on some advice I found in another forum, my goal was to intercept the ComboBox message <code>LB_FINDSTRING</code> and replace it with <code>LB_FINDSTRINGEXACT</code>.  The post suggested that ComboBox defaulted to <code>LB_FiNDSTRING</code>, which fits what I see it doing, and that subbing <code>LB_FINDSTRINGEXACT</code> would cure the problem.  Trouble is, unless I got a bad definition for <code>LB_FINDSTRING</code>, it was never received.</p>
  
  <p>Here's my enum:</p>
  
  <pre><code>[Flags]
  public enum ListBoxFlags
  {
      LB_ADDSTRING = 0x0180,
      LB_SETSEL = 0x0185,
      LB_GETSELITEMS = 0x0191,
      LB_GETSELCOUNT = 0x0190,
      LB_GETCURSEL = 0x0188,
      LB_SELECTSTRING = 0x018C,
      LB_SETCURSEL = 0x0186,
      LB_FINDSTRING = 0x018F,
      LB_FINDSTRINGEXACT = 0x01A2,
      LB_GETCOUNT = 0x018B,
      LB_GETSEL = 0x0187,
      LB_GETTEXT = 0x0189,
      LB_RESETCONTENT = 0x0184,
      LB_SETHORIZONTALEXTENT = 0x0194,
      LB_GETHORIZONTALEXTENT = 0x0193,
      LB_GETTOPINDEX = 0x018E,
      LB_SETTOPINDEX = 0x0197,
      LB_INSERTSTRING = 0x0181,
      LB_DELETESTRING = 0x0182,
      LB_GETITEMDATA = 0x0199
  }
  </code></pre>