Recent

Author Topic: LookUpComboBox incremental search limit to item list  (Read 11411 times)

99Percent

  • Full Member
  • ***
  • Posts: 160
LookUpComboBox incremental search limit to item list
« on: December 09, 2010, 07:05:11 am »
Is there a (simple) way to limit the keystroke input of the incremental search to items in the LookUpComboBox (and particularly DBLookUpComboBox).

For example if there is the following items listed in the LookUpComboBox:

Batman
Spiderman
Superman

And a user user types "S" the only keypress value allowed would be "p" and "u", and if he then types "p" the only keypress value would then be "i". It totally messes up data validation if the user can type any text in the control.

It would be great if there were a property such as "LimitToList" that will control this behaviour. I have looked into the code and unfortunately I see no easy way to do this, or I am missing something obvious.

krexon

  • Jr. Member
  • **
  • Posts: 80
Re: LookUpComboBox incremental search limit to item list
« Reply #1 on: December 09, 2010, 02:24:14 pm »
I wrote about it concering ComboBox in post:
http://lazarus.freepascal.org/index.php/topic,10767.0.html

I have app with 50-60 (in the group of 100 others) items with the same few first letters and I would like to have ability like in Delphi :(

99Percent

  • Full Member
  • ***
  • Posts: 160
Re: LookUpComboBox incremental search limit to item list
« Reply #2 on: December 09, 2010, 04:23:39 pm »
The latest SVN version does the behavior you describe if the list is in order. But the user can still input any text even if its not in the list of the lookup.

So in your example the user can type "CAB" but also "CAR".

krexon

  • Jr. Member
  • **
  • Posts: 80
Re: LookUpComboBox incremental search limit to item list
« Reply #3 on: December 09, 2010, 10:12:44 pm »
Yes I know this behaviour, but in Delphi when I set style to DropDownList I can still type letters CAB and combo selects 'CAB' item. In Lazarus when I press C focus is set on 'CAB', then I press A and focus is set to 'ABC' instead of staying on CAB.
I can set amount of time in AutoComplete after which it behaves as in Lazarus.

99Percent

  • Full Member
  • ***
  • Posts: 160
Re: LookUpComboBox incremental search limit to item list
« Reply #4 on: December 10, 2010, 07:16:15 pm »
krexon, that behavior you describe doesn't occur in my version of Lazarus (28578).

Anyway I solved my problem by adding the following code in the OnKeyPress event of the DBLookUpComboBox:
Code: [Select]
procedure TFMEditArt.MyDBLookUpComboBoxKeyPress(Sender: TObject; var Key: char);
  var
  sText : String;
  sSelStart : Integer;
begin
  if (Ord(key)>31) then with Sender as TDBLookUpComboBox do begin
    sSelStart:=SelStart+1; //simulate that the key has been added
    sText:=Copy(Text,1,sSelStart-1)+Key;
    if Items.IndexOf(GetCompleteText(sText, sSelStart,(cbactSearchCaseSensitive in AutoCompleteText),
                                       (cbactSearchAscending in AutoCompleteText), Items))=-1
      then Key:=#0;
  end;
end;

Also add LCLProc in the uses clause for the GetCompleteText function.

Its obviously not perfect. No provision for UTF characters to begin, with but it works for now.

krexon

  • Jr. Member
  • **
  • Posts: 80
Re: LookUpComboBox incremental search limit to item list
« Reply #5 on: December 10, 2010, 09:53:03 pm »
I noticed this problem few months ago. I've checked minute ago in 0.9.29 SVN 28656 FPC 2.5.1 and the problem sill exists.

 

TinyPortal © 2005-2018