Recent

Author Topic: Combo Box Behavior  (Read 5106 times)

whiffee

  • New Member
  • *
  • Posts: 18
Combo Box Behavior
« on: May 21, 2017, 09:30:29 pm »
I have a problem with the Combo Box. I assign a long list of items, pre-alphabetized, and then I may search for a starting string. In code written in Delphi 5 the behavior is as follows: the closest match is shown in the Combo Box edit field. If the list is dropped down, the search point is displayed, with items before and after and the match item in the middle. Good.

The same code compiled by Lazarus 1.6 does not behave this way. The search runs and succeeds, and the match is shown in the edit field. But when the list is dropped down, the top of the list only is shown. The match is nowhere to be seen. Maybe I'm not populating the item list the right way. Below is some code. Any suggestions are appreciated.

procedure TForm1.GetData(Sender: TObject);
var
   lines, i, j, lastverb, lastverbplus : Integer;
   verbname : string;
begin
   fileData := TStringList.Create;
   fileData.LoadFromFile('Verb12Data.txt');
   lines := fileData.Count;
   verbname := '';

   if frac(lines / 395) <> 0.0000 then PJVCLMsgDlg1.execute; 
   lastverb := (lines div 396);

   lastverbplus := (lastverb div 395);
   lastverb := lastverb + lastverbplus;

    for i := 0 to lastverb do begin
    j := 395*i;
    verbname := fileData[j];
    Delete(verbname, 1, 30);
    ComboBox1.Items.Add(' ' + verbname);
    end;

    ComboBox1.Itemindex := 0;
    RefreshEBoxes(Sender);
   
end;   

thanks,
Whiffee                                   
 

valdir.marcos

  • Hero Member
  • *****
  • Posts: 1106
Re: Combo Box Behavior
« Reply #1 on: May 21, 2017, 11:27:09 pm »
I have a problem with the Combo Box. I assign a long list of items, pre-alphabetized, and then I may search for a starting string. In code written in Delphi 5 the behavior is as follows: the closest match is shown in the Combo Box edit field. If the list is dropped down, the search point is displayed, with items before and after and the match item in the middle. Good.

The same code compiled by Lazarus 1.6 does not behave this way. The search runs and succeeds, and the match is shown in the edit field. But when the list is dropped down, the top of the list only is shown. The match is nowhere to be seen. Maybe I'm not populating the item list the right way. Below is some code. Any suggestions are appreciated.


This simple example in Lazarus 1.6.4 behaves just the way you explained in Delphi5:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3.   ComboBox1.AutoComplete := True;
  4.   ComboBox1.Clear;
  5.   ComboBox1.Items.Clear;
  6.   ComboBox1.Items.Add('aaa');
  7.   ComboBox1.Items.Add('bbb');
  8.   ComboBox1.Items.Add('ccc');
  9.   ComboBox1.Items.Add('ddd');
  10.   ComboBox1.Items.Add('eee');
  11.   ComboBox1.Items.Add('fff');
  12.   ComboBox1.Items.Add('ggg');
  13.   ComboBox1.Items.Add('hhh');
  14.   ComboBox1.Items.Add('iii');
  15.   ComboBox1.Items.Add('jjj');
  16.   ComboBox1.SetFocus;
  17. end;

whiffee

  • New Member
  • *
  • Posts: 18
Re: Combo Box Behavior
« Reply #2 on: May 22, 2017, 01:52:12 am »
My question was not very clear. If the Combo Box has less than 25 items, a dropdown will always show them all. I tried your snippet with 49 items, then executed a procedure to show one with an index number greater than 25, the same thing a search would do. The item appeared in the edit box, but not in the dropdown.

I can ask my question another way: Is there any way to get a Combo Box dropdown  that does not show the top of the list? My understanding of Laz is poor, but I suspect the answer is no.

Thanks for your reply by the way.

regards, Whiffee

 

valdir.marcos

  • Hero Member
  • *****
  • Posts: 1106
Re: Combo Box Behavior
« Reply #3 on: May 22, 2017, 03:20:02 am »
My question was not very clear. If the Combo Box has less than 25 items, a dropdown will always show them all. I tried your snippet with 49 items, then executed a procedure to show one with an index number greater than 25, the same thing a search would do. The item appeared in the edit box, but not in the dropdown.

I can ask my question another way: Is there any way to get a Combo Box dropdown  that does not show the top of the list? My understanding of Laz is poor, but I suspect the answer is no.

Maybe, you should make a video (and convert it to GIF), so we can better understand your viewpoint.
Meanwhile, try this:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.   i, j, k: byte;
  4. begin
  5.   ComboBox1.AutoComplete := True;
  6.   ComboBox1.Clear;
  7.   ComboBox1.Items.Clear;
  8.   for i := 97 to 122 do
  9.     for j := 97 to 122 do
  10.       for k := 97 to 122 do
  11.         ComboBox1.Items.Add(chr(i)+chr(j)+chr(k));
  12.   ComboBox1.SetFocus;
  13. end;

HeavyUser

  • Sr. Member
  • ****
  • Posts: 397
Re: Combo Box Behavior
« Reply #4 on: May 22, 2017, 03:26:43 am »
Maybe, you should make a video (and convert it to GIF), so we can better understand your viewpoint.
He probably means that the drop down list does not Auto scroll to the selected item when opened. Probably only when the selection is done from code or some other set of conditions not well defined at this point.

valdir.marcos

  • Hero Member
  • *****
  • Posts: 1106
Re: Combo Box Behavior
« Reply #5 on: May 22, 2017, 03:35:44 am »
Maybe, you should make a video (and convert it to GIF), so we can better understand your viewpoint.
He probably means that the drop down list does not Auto scroll to the selected item when opened. Probably only when the selection is done from code or some other set of conditions not well defined at this point.

Maybe this other one:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.   i, j, k: byte;
  4. begin
  5.   ComboBox1.AutoComplete := True;
  6.   ComboBox1.AutoDropDown := True;
  7.   ComboBox1.Clear;
  8.   ComboBox1.Items.Clear;
  9.   for i := 97 to 122 do
  10.     for j := 97 to 122 do
  11.       for k := 97 to 122 do
  12.         ComboBox1.Items.Add(chr(i)+chr(j)+chr(k));
  13.   ComboBox1.SetFocus;
  14. end;

whiffee

  • New Member
  • *
  • Posts: 18
Re: Combo Box Behavior
« Reply #6 on: May 22, 2017, 05:03:34 am »
hi valdir, thanks for your attention. I tried your latest code variation and I'm still getting the same thing. (Two browsers in Linux and two in OSX are refusing to show a forum post 'reply' icon, so I'm pecking this out on a tablet.)

As for the problem description, suppose I have 5000 items in a Combo Box and I'm doing a search. The items are strings but I'm interested in results that are close to the best match. The best match is available in the text box, but there's no way I'm going to be able to scroll by hand to the result's location to examine the near results.
 
I realize there are other ways to approach this, but for now a combo box is a convenient container that can easily be manipulated from the U/I, and repeated searches done with quick results available.

If HeavyUser doesn't mind my putting in a piggy-backed response, the term 'AutoScroll' seems to fit well. Does TComboBox have such a thing?

Thanks again for following.
regards,
Whiffee


valdir.marcos

  • Hero Member
  • *****
  • Posts: 1106
Re: Combo Box Behavior
« Reply #7 on: May 22, 2017, 06:09:52 am »
There are 17,576 items (263 or 26 x 26 x 26) in my combobox example.
In my example, type "def", then press arrow down and up on your keyboard.
That is a possible solution where you can navigate on the combobox near search result.
Beyond that, I need a video to understand what exactly you mean.
« Last Edit: May 22, 2017, 05:13:27 pm by valdir.marcos »

whiffee

  • New Member
  • *
  • Posts: 18
Re: Combo Box Behavior
« Reply #8 on: May 22, 2017, 04:15:46 pm »
hi valdir,
My last post was not posted for some reason. I observed that the trick with the arrow keys is a good one to know about. By clicking at the right time it is not necessary to re-select the contents of the edit box to go up one item or down one. Still, this solution does not equal the convenience of being able to see the box index point and its surroundings at one glance.
thanks much for your help.
regards, whiffee


valdir.marcos

  • Hero Member
  • *****
  • Posts: 1106
Re: Combo Box Behavior
« Reply #9 on: May 22, 2017, 05:12:37 pm »
You're welcome.

 

TinyPortal © 2005-2018