Recent

Author Topic: Custom Text in "DropDownList - Combobox"  (Read 1050 times)

Weitentaaal

  • Hero Member
  • *****
  • Posts: 503
  • Weitental is a very beautiful garbage depot.
Custom Text in "DropDownList - Combobox"
« on: August 22, 2022, 09:26:49 am »
Hello,

i have a Combobox with the style "csDropDownList". I want to be able to display old selection that is no more selectable.

Example:
Items Avaiable at old State:
  • Produkt1
  • Produkt2

Items Avaiable now (Changed itemlist)
  • Produkt1
  • Produkt3(New)

in this case the Produkt2 was replaced with produkt3. now if Someone is loading old Data where the user did select Produkt2, i wanna show that in the combobox.
Currently using this:

Code: Pascal  [Select][+][-]
  1. ComboXYZ.Text:= SelectedProdukt;
  2.  

but i cant assign the string if its not in the list(ReadOnly = True). Can i somehow achiev this ?
Lazarus: 2.0.12 x86_64-win64-win32/win64
Compiler Version: 3.2.2

Nicole

  • Hero Member
  • *****
  • Posts: 970
Re: Custom Text in "DropDownList - Combobox"
« Reply #1 on: August 22, 2022, 03:43:43 pm »
you can enforce a label into the combobox.

How this is done, you will find here:
https://lazplanet.blogspot.com/2013/12/create-rich-text-editor-for-yourself.html

The menu-bar has a font-combobox and there you will find it.

Weitentaaal

  • Hero Member
  • *****
  • Posts: 503
  • Weitental is a very beautiful garbage depot.
Re: Custom Text in "DropDownList - Combobox"
« Reply #2 on: August 24, 2022, 09:43:51 am »
you can enforce a label into the combobox.

How this is done, you will find here:
https://lazplanet.blogspot.com/2013/12/create-rich-text-editor-for-yourself.html

The menu-bar has a font-combobox and there you will find it.


Thanks !

But my Problem is that i want to write into a ReadOnly Combobox. Just to Display previous Selection when the item is no more in the Combobox.

If i put a Label into the Combobox i wont get the "higlightet - Color" what a combo gests when u hover over it. I think thats a dirty way of doing that too so i was asking what i can do.
Lazarus: 2.0.12 x86_64-win64-win32/win64
Compiler Version: 3.2.2

Zvoni

  • Hero Member
  • *****
  • Posts: 2319
Re: Custom Text in "DropDownList - Combobox"
« Reply #3 on: August 24, 2022, 10:22:02 am »
I don't understand, why you have "ReadOnly"
It's a DropDownLIST, so the User cannot add from the GUI a new Entry.
From Code you can add whatever you want
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

Weitentaaal

  • Hero Member
  • *****
  • Posts: 503
  • Weitental is a very beautiful garbage depot.
Re: Custom Text in "DropDownList - Combobox"
« Reply #4 on: August 24, 2022, 10:27:38 am »
I don't understand, why you have "ReadOnly"
It's a DropDownLIST, so the User cannot add from the GUI a new Entry.
From Code you can add whatever you want

Hey yes i can but i dont want to add the item to the list i just want to show the user the last selection. Maybe if he reopens the Application after 2 years with the same Project. Some Selections might not be avaiable anymore and i just want to show old Data. But i don't want him to be able to Select the Old Selection.

Edit: https://forum.lazarus.freepascal.org/index.php?topic=31092.0
this is an old Thread to describe my problem. i do not realy like this Solution so i asked if there is any better
« Last Edit: August 24, 2022, 10:31:29 am by Weitentaaal »
Lazarus: 2.0.12 x86_64-win64-win32/win64
Compiler Version: 3.2.2

Nicole

  • Hero Member
  • *****
  • Posts: 970
Re: Custom Text in "DropDownList - Combobox"
« Reply #5 on: August 24, 2022, 10:47:04 am »
What will happen, if there are 3 changes in 2 years?

This solution may turn out to be too casuistig (can we say this in English?) in 5 years.
It is up to you, I would work with a label or a speed button, which you can color blue by code if the user selects one item.
Such a label, panel or speedbutton can even be invisible if the combobox is "off".

Weitentaaal

  • Hero Member
  • *****
  • Posts: 503
  • Weitental is a very beautiful garbage depot.
Re: Custom Text in "DropDownList - Combobox"
« Reply #6 on: August 24, 2022, 10:53:05 am »
What will happen, if there are 3 changes in 2 years?

This solution may turn out to be too casuistig (can we say this in English?) in 5 years.
It is up to you, I would work with a label or a speed button, which you can color blue by code if the user selects one item.
Such a label, panel or speedbutton can even be invisible if the combobox is "off".

yes i currently tried to use a TLabel which is in the middle of the combobox.

i used this Code but unfortunately the Combobox wont expand (i guess bc the label gets the focus when i set a Caption). i will work a bit on it i think i am on a good way.
i set Label Parent to combobox so it will get drawn over it, but unfortunately that brings more problems then i thought. anyway i will post my solution if i find one.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.ComboBox1Select(Sender: TObject);
  2. begin
  3.    if ComboBox1.ItemIndex = -1 then begin
  4.      Label1.Caption:= 'TEST';
  5.    end;
  6. end;
  7.  
« Last Edit: August 24, 2022, 10:56:58 am by Weitentaaal »
Lazarus: 2.0.12 x86_64-win64-win32/win64
Compiler Version: 3.2.2

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: Custom Text in "DropDownList - Combobox"
« Reply #7 on: August 24, 2022, 11:02:26 am »
Hey yes i can but i dont want to add the item to the list i just want to show the user the last selection. Maybe if he reopens the Application after 2 years with the same Project. Some Selections might not be avaiable anymore and i just want to show old Data. But i don't want him to be able to Select the Old Selection.
This would be a too confusing user interface to me. A combobox is there to make selections (unless it's ReadOnly). Why should there be items that I cannot select? You should rethink this. Maybe: When there is an old item, set the Combobox.ItemIndex to -1 and show a label beneath the combobox saying: "Previously selected item "<something>" no longer available."

Weitentaaal

  • Hero Member
  • *****
  • Posts: 503
  • Weitental is a very beautiful garbage depot.
Re: Custom Text in "DropDownList - Combobox"
« Reply #8 on: August 24, 2022, 11:17:09 am »
Hey yes i can but i dont want to add the item to the list i just want to show the user the last selection. Maybe if he reopens the Application after 2 years with the same Project. Some Selections might not be avaiable anymore and i just want to show old Data. But i don't want him to be able to Select the Old Selection.
This would be a too confusing user interface to me. A combobox is there to make selections (unless it's ReadOnly). Why should there be items that I cannot select? You should rethink this. Maybe: When there is an old item, set the Combobox.ItemIndex to -1 and show a label beneath the combobox saying: "Previously selected item "<something>" no longer available."

yes you are right but i can't decide this, thats what my prefixed wants. im currently using a static text and i got it all together but i cant make the static text transparent / give it the same color as the combobox.
Lazarus: 2.0.12 x86_64-win64-win32/win64
Compiler Version: 3.2.2

dje

  • Full Member
  • ***
  • Posts: 134
Re: Custom Text in "DropDownList - Combobox"
« Reply #9 on: August 24, 2022, 11:29:46 am »
What about adding the unavailable product to the combbox item list with modified text? Assuming you have a list of available products, you can set your TComboBox text using:

Code: Pascal  [Select][+][-]
  1. procedure ProductSetText(AComboBox: TComboBox; AProduct, AProductList: string);
  2. begin
  3.   AComboBox.Items.CommaText := AProductList;
  4.   if AComboBox.Items.IndexOf(AProduct) = -1 then begin
  5.     AProduct := AProduct + ' (Not Avaliable)';
  6.     AComboBox.Items.Add(AProduct);
  7.   end;
  8.   AComboBox.Text := AProduct;
  9.   if Assigned(AComboBox.OnChange) then begin
  10.     AComboBox.OnChange(AComboBox);
  11.   end;
  12. end;  

You can then indicate the product is unavailable via font text color:
Code: Pascal  [Select][+][-]
  1. procedure TFormMain.ComboBox1Change(Sender: TObject);
  2. begin
  3.   if Pos('(', ComboBox1.Text) = 0 then begin // Use a better method of detecting invalid product
  4.     ComboBox1.Font.Color := clDefault;
  5.   end else begin
  6.     ComboBox1.Font.Color := clRed;
  7.   end;
  8. end;  

Weitentaaal

  • Hero Member
  • *****
  • Posts: 503
  • Weitental is a very beautiful garbage depot.
Re: Custom Text in "DropDownList - Combobox"
« Reply #10 on: August 24, 2022, 12:33:55 pm »
What about adding the unavailable product to the combbox item list with modified text? Assuming you have a list of available products, you can set your TComboBox text using:

Code: Pascal  [Select][+][-]
  1. procedure ProductSetText(AComboBox: TComboBox; AProduct, AProductList: string);
  2. begin
  3.   AComboBox.Items.CommaText := AProductList;
  4.   if AComboBox.Items.IndexOf(AProduct) = -1 then begin
  5.     AProduct := AProduct + ' (Not Avaliable)';
  6.     AComboBox.Items.Add(AProduct);
  7.   end;
  8.   AComboBox.Text := AProduct;
  9.   if Assigned(AComboBox.OnChange) then begin
  10.     AComboBox.OnChange(AComboBox);
  11.   end;
  12. end;  

You can then indicate the product is unavailable via font text color:
Code: Pascal  [Select][+][-]
  1. procedure TFormMain.ComboBox1Change(Sender: TObject);
  2. begin
  3.   if Pos('(', ComboBox1.Text) = 0 then begin // Use a better method of detecting invalid product
  4.     ComboBox1.Font.Color := clDefault;
  5.   end else begin
  6.     ComboBox1.Font.Color := clRed;
  7.   end;
  8. end;  

Thanks for your suggestion and Thanks to everyone else. With your suggestions i will surely be able to create something that works :)
Lazarus: 2.0.12 x86_64-win64-win32/win64
Compiler Version: 3.2.2

Zvoni

  • Hero Member
  • *****
  • Posts: 2319
Re: Custom Text in "DropDownList - Combobox"
« Reply #11 on: August 24, 2022, 03:02:13 pm »
Here's a "Solution" for Delphi:
https://stackoverflow.com/questions/5583835/delphi-is-it-possible-to-have-a-combo-box-with-disabled-items-in-it

Sounds like your "Problem": Adding Items to a ComboBox, but disable specific Items to be selectable
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

Nicole

  • Hero Member
  • *****
  • Posts: 970
Re: Custom Text in "DropDownList - Combobox"
« Reply #12 on: August 24, 2022, 05:00:41 pm »

Code: Text  [Select][+][-]
  1. yes you are right but i can't decide this, thats what my prefixed wants. im currently using a static text and i got it all together but i cant make the static text transparent / give it the same color as the combobox.

you can try this:
- right click the static text
- choose change class
- change to speed button
- set enable to false

Now you have a "static text" which allows your formatting. Hint: Set style to "flat"

 

TinyPortal © 2005-2018