Recent

Author Topic: stop tcheckcombobox from dropping down with one item  (Read 955 times)

Joanna

  • Jr. Member
  • **
  • Posts: 67
stop tcheckcombobox from dropping down with one item
« on: October 05, 2021, 12:37:26 pm »
i want to prevent it from dropping down when it contains less than two items.

I've tried changing it to a simple style combobox and the check box part goes away and it looks horrible.

i tried this
Code: Pascal  [Select][+][-]
  1. TMyCheckComboBox= CLASS (TCheckComboBox)  // i need this to control the colors of the checkcombobox
  2.  PROTECTED   //this is modified code from tcustomcheckcombobox.drawitem
  3.    PROCEDURE DROPDOWN; OVERRIDE; // do not allow dropdown when there is only one item
  4.    PROCEDURE DRAWITEM( INDEX: INTEGER; ARECT: TRECT; MYSTATE: TOWNERDRAWSTATE) ; OVERRIDE;
  5.  END;    
  6.  
  7.  PROCEDURE TMYCHECKCOMBOBOX.DROPDOWN;
  8. BEGIN
  9. IF (Count < 2 )
  10.    THEN CloseUp;
  11. END;
  12.  

it goes into this procedure but it doesn't seem to close it .
i dont understand how to close it ?
« Last Edit: October 06, 2021, 03:20:52 am by Joanna »
Come chat on IRC .. IRC.LIBERA.CHAT  Ports [6667 plaintext ] or [SASL 6697] channels  #fpc #lazarus #pascal

ASerge

  • Hero Member
  • *****
  • Posts: 1885
Re: how to stop tcheckcombobox from dropping down ?
« Reply #1 on: October 05, 2021, 09:21:30 pm »
i want to prevent it from dropping down when it contains less than two items.
Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, StdCtrls;
  9.  
  10. type
  11.   TForm1 = class(TForm)
  12.     btnAddComboItem: TButton;
  13.     btnDelComboItem: TButton;
  14.     ComboBox1: TComboBox;
  15.     procedure btnAddComboItemClick(Sender: TObject);
  16.     procedure btnDelComboItemClick(Sender: TObject);
  17.     procedure FormCreate(Sender: TObject);
  18.   private
  19.   end;
  20.  
  21. var
  22.   Form1: TForm1;
  23.  
  24. implementation
  25.  
  26. {$R *.lfm}
  27.  
  28. procedure CheckItemsCount(Cmb: TComboBox);
  29. begin
  30.   case Cmb.Items.Count of
  31.     0:
  32.       begin
  33.         Cmb.Style := csSimple;
  34.         Cmb.Text := '';
  35.       end;
  36.     1:
  37.       begin
  38.         Cmb.Style := csSimple;
  39.         Cmb.ItemIndex := 0;
  40.       end;
  41.   else
  42.     Cmb.Style := csDropDown;
  43.     Cmb.ItemIndex := Cmb.Items.Count - 1;
  44.   end;
  45. end;
  46.  
  47. procedure TForm1.btnAddComboItemClick(Sender: TObject);
  48. begin
  49.   ComboBox1.Items.Append(TimeToStr(Time));
  50.   CheckItemsCount(ComboBox1);
  51. end;
  52.  
  53. procedure TForm1.btnDelComboItemClick(Sender: TObject);
  54. begin
  55.   if ComboBox1.Items.Count > 0 then
  56.   begin
  57.     ComboBox1.Items.Delete(ComboBox1.Items.Count - 1);
  58.     CheckItemsCount(ComboBox1);
  59.   end;
  60. end;
  61.  
  62. procedure TForm1.FormCreate(Sender: TObject);
  63. begin
  64.   CheckItemsCount(ComboBox1);
  65. end;
  66.  
  67. end.

Joanna

  • Jr. Member
  • **
  • Posts: 67
Re: how to stop tcheckcombobox from dropping down ?
« Reply #2 on: October 06, 2021, 02:04:54 am »
aserge thank you for the sample project. please substitute  tcheckcombobox into there and see what happens . on my computer the checkbox disappears and the whole thing becomes editable.

the behavior i want is for it just to look like a checkbox that can be checked.

to be fair i just tried to test this witth my lazarus linux client 2.0.10
and it didnt look any better. Then i noticed these messages

project1.lpr(21,1) Warning: "crtbeginS.o" not found, this will probably cause a linking failure
project1.lpr(21,1) Warning: "crtendS.o" not found, this will probably cause a linking failure

i dont really know what to do about these things or if they are related.
logically the cssimple style is not custom drawn so in a best case scenerio the colors will be wrong.

I tested with Lazarus Mac OS version 2.0.4 Which has several problems. The selected item string appears twice instead of showing the checkbox and item.
When the edit portion of the checkcombobox is clicked it shows a blank box. If the arrows part is clicked  or down arrow key is used it will sort of popup the list of items and checkboxes and they can be changed there Only by clicking With mouse. Space key has no affect.
Not being able to see if the item is checked without opening it is a major detraction I think.
« Last Edit: October 06, 2021, 02:41:34 am by Joanna »
Come chat on IRC .. IRC.LIBERA.CHAT  Ports [6667 plaintext ] or [SASL 6697] channels  #fpc #lazarus #pascal

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2718
    • havefunsoft.com
Re: how to stop tcheckcombobox from dropping down ?
« Reply #3 on: October 06, 2021, 05:02:31 am »
I tested with Lazarus Mac OS version 2.0.4 Which has several problems. The selected item string appears twice instead of showing the checkbox and item.
This is a known issue. That has been fixed
Are you looking for the fix specifically in version 2.0.4?

Joanna

  • Jr. Member
  • **
  • Posts: 67
Re: stop tcheckcombobox from dropping down with one item
« Reply #4 on: October 06, 2021, 07:00:22 am »
I’m glad it was fixed on the Mac OS.
Does anyone have any clues on how to fix whatever is causing the warnings  in Linux client? I’m using fedora linux.
Come chat on IRC .. IRC.LIBERA.CHAT  Ports [6667 plaintext ] or [SASL 6697] channels  #fpc #lazarus #pascal

 

TinyPortal © 2005-2018