Recent

Author Topic: Tedit and combobox  (Read 6077 times)

jjsantos

  • Newbie
  • Posts: 1
Tedit and combobox
« on: April 26, 2015, 06:18:31 am »
Hi everyone!

I am develop a simple application in Lazarus to learn this language.
In this applicatio I have to do:

When I click on a tedit (on the form there are 05 tedit and 01 combobox that has the visible=false). The combobox items is added by accord of the tedit clicked. For example: tedit1=class, tedit2=type, tedit3=name... . When I click tedit1, filled the combobox, show it in dropdown style, then I select a item, close de combobox and send the value selected to the edit1. If I click on tedit2, show the same combobox with items relatives to this tedit2, select a item, send the value to tedit2 and so on...

I don´t to use combobox because the apperance of it. It has a arrow dropdown and I want a more clean component to show the data (as a tedit).

Is there a way to do this?

Thanks.

jjsantos.
how to do this.

I´d like a exemple that show how do.

thanks for any help.

jjsantos.
« Last Edit: April 26, 2015, 07:40:11 pm by jjsantos »

munair

  • Hero Member
  • *****
  • Posts: 798
  • compiler developer @SharpBASIC
    • SharpBASIC
Re: Tedit and combobox
« Reply #1 on: April 26, 2015, 07:33:00 am »
I do not think you can generate combobox open (popup) programmatically. The user will have to click on the combobox and then on an item that you can then put in TEdit by using the combobox change event:

Code: [Select]
procedure TForm1.ComboBox1Change(Sender: TObject);
begin
  Edit1.Text = ComboBox1.Items.Strings[ComboBox1.ItemIndex];
end;
keep it simple

eric

  • Sr. Member
  • ****
  • Posts: 267
Re: Tedit and combobox
« Reply #2 on: April 26, 2015, 08:23:23 am »
Surely that's what a combobox does all by itself. You can edit the text (i.e. use it like a TEdit) or click on it and select an item from the drop-down list.

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Tedit and combobox
« Reply #3 on: April 26, 2015, 09:27:03 am »
Surely that's what a combobox does all by itself. You can edit the text (i.e. use it like a TEdit) or click on it and select an item from the drop-down list.
why not use a combobox instead of tedit? in any case to force a combobox to show its dropdown list you simple set the   DroppedDown property to true ee
Code: [Select]
ComboBox1.DroppedDown :=True;
You can for example place both controls on the same spot on the form have the combobox behind the tedit show it will not be visible and on the onclick event of the tedit set the combobox's droppeddown property to true. After that you can use the combobox's events to decide when to copy the data back to tedit but I don't understand why not show the combobox only?

Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

munair

  • Hero Member
  • *****
  • Posts: 798
  • compiler developer @SharpBASIC
    • SharpBASIC
Re: Tedit and combobox
« Reply #4 on: April 26, 2015, 12:15:34 pm »
Surely that's what a combobox does all by itself. You can edit the text (i.e. use it like a TEdit) or click on it and select an item from the drop-down list.
why not use a combobox instead of tedit?
The OP asked a way to transfer combobox text to an edit field. There are situations where this is necessary if you want the combobox to act as a drop down list. I have such a program.

Thanks for showing the DroppedDown property. Maybe I'll need it in the future.
keep it simple

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Tedit and combobox
« Reply #5 on: April 26, 2015, 12:24:39 pm »
Surely that's what a combobox does all by itself. You can edit the text (i.e. use it like a TEdit) or click on it and select an item from the drop-down list.
why not use a combobox instead of tedit?
The OP asked a way to transfer combobox text to an edit field. There are situations where this is necessary if you want the combobox to act as a drop down list. I have such a program.
I have no idea why this is necessary. I never used an TEdit in place of a TCombobox  and never had the need to show only the drop down list of the combo box and move the text to an edit. Even that is fairly simple just access something like combobox1.text or combobox1.items[combobox1.Itemindex] to get the text. BUT why have a second control to show the selected data when a combo box can behave both as a free typing edit with a list of predefined values or a strict list selection with out the ability to type at all. I see the point in the question I guess so fill free to use what ever hints I provided or ask more specific questions.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

munair

  • Hero Member
  • *****
  • Posts: 798
  • compiler developer @SharpBASIC
    • SharpBASIC
Re: Tedit and combobox
« Reply #6 on: April 26, 2015, 02:39:22 pm »
Here is an example of a program I wrote to do research on earthquakes. In the upper left I can choose the date of a magnitude 8+ earthquake. That date will then be copied into the text field and then the calculations will be done. But with the text field I can also enter any date I want to do calculations on. This is very convenient and it won't mess up the combobox list. ;)
keep it simple

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Tedit and combobox
« Reply #7 on: April 26, 2015, 02:49:39 pm »
Here is an example of a program I wrote to do research on earthquakes. In the upper left I can choose the date of a magnitude 8+ earthquake. That date will then be copied into the text field and then the calculations will be done. But with the text field I can also enter any date I want to do calculations on. This is very convenient and it won't mess up the combobox list. ;)
You have described one of the two use cases of a combobox, it already supports this with out the need of any extra controls. Lets just leave it at that for now.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

munair

  • Hero Member
  • *****
  • Posts: 798
  • compiler developer @SharpBASIC
    • SharpBASIC
Re: Tedit and combobox
« Reply #8 on: April 26, 2015, 04:05:08 pm »
Here is an example of a program I wrote to do research on earthquakes. In the upper left I can choose the date of a magnitude 8+ earthquake. That date will then be copied into the text field and then the calculations will be done. But with the text field I can also enter any date I want to do calculations on. This is very convenient and it won't mess up the combobox list. ;)
You have described one of the two use cases of a combobox, it already supports this with out the need of any extra controls. Lets just leave it at that for now.
The fact that you do not see how this can be useful does not mean that it is not. In my program the combobox and the edit field both have buttons next to them. With the combobox I can skip from one predefined date to the next forwards and backwards. With the edit field I can skip a date one day at a time. I need both and this way it saves me a lot of date typing.

Imagination is the virtue of a programmer.
keep it simple

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Tedit and combobox
« Reply #9 on: April 26, 2015, 07:08:47 pm »
Here is an example of a program I wrote to do research on earthquakes. In the upper left I can choose the date of a magnitude 8+ earthquake. That date will then be copied into the text field and then the calculations will be done. But with the text field I can also enter any date I want to do calculations on. This is very convenient and it won't mess up the combobox list. ;)
You have described one of the two use cases of a combobox, it already supports this with out the need of any extra controls. Lets just leave it at that for now.
The fact that you do not see how this can be useful does not mean that it is not. In my program the combobox and the edit field both have buttons next to them. With the combobox I can skip from one predefined date to the next forwards and backwards. With the edit field I can skip a date one day at a time. I need both and this way it saves me a lot of date typing.

Imagination is the virtue of a programmer.
Useful? Who said anything about useful? The only think I said is that up until now you described to the letter the use case of a single combo box. The fact that you used 2 controls does not make it any more or less useful just wasteful. My understanding or acceptance is not required I'm not your customer.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

munair

  • Hero Member
  • *****
  • Posts: 798
  • compiler developer @SharpBASIC
    • SharpBASIC
Re: Tedit and combobox
« Reply #10 on: April 26, 2015, 07:15:33 pm »
Here is an example of a program I wrote to do research on earthquakes. In the upper left I can choose the date of a magnitude 8+ earthquake. That date will then be copied into the text field and then the calculations will be done. But with the text field I can also enter any date I want to do calculations on. This is very convenient and it won't mess up the combobox list. ;)
You have described one of the two use cases of a combobox, it already supports this with out the need of any extra controls. Lets just leave it at that for now.
The fact that you do not see how this can be useful does not mean that it is not. In my program the combobox and the edit field both have buttons next to them. With the combobox I can skip from one predefined date to the next forwards and backwards. With the edit field I can skip a date one day at a time. I need both and this way it saves me a lot of date typing.

Imagination is the virtue of a programmer.
Useful? Who said anything about useful? The only think I said is that up until now you described to the letter the use case of a single combo box. The fact that you used 2 controls does not make it any more or less useful just wasteful. My understanding or acceptance is not required I'm not your customer.
Obviously we're communicating on different levels here. Useless to waste any more time on this.
keep it simple

 

TinyPortal © 2005-2018