?
Solved

Change combobox text

Posted on 2003-02-21
8
Medium Priority
?
3,313 Views
Last Modified: 2010-07-27
I am trying to change the combobox text on selection.

What I am doing is the following:

I fill the list with a set of strings read out from an ini file.
On selection I want to replace the string with a value associated with the string.

For example the ini file has the entry:

power cycle=a5 00 05 50

The the list shows "power cycle", when the user selects the entry the edit box is supposed to show "a5 00 05 50"

I am using the "OnSelect" event in Delphi to change the text property but the change does not show up. When I trace through the code all variables are fine and perform correctly. I assume that another event is happening that I am not aware of that resets the text property back to the list entry.

I am using Delphi 6
0
Comment
Question by:gsteup
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7994311
what combobox-style do you use?
0
 
LVL 3

Expert Comment

by:sfock
ID: 7994315
use OnChange or probably onClick and code

if cb.itemIndex >= 0 then
  cb.text := privAssociatedTextTo(cb.items[]);
0
 
LVL 3

Expert Comment

by:sfock
ID: 7994329
uups
i meant
if cb.itemIndex >= 0 then
 cb.text := privAssociatedTextTo(cb.items[cb.itemIndex]);

and yes kretzschmar is right the syle should not be csDropDownList
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Author Comment

by:gsteup
ID: 7994511
Ok,

kretzschmar:
the style is csDropDown

sfock:
I used OnChange
and even hardcoded a string:

procedure TForm1.ComboBox3Change(Sender: TObject);

begin
  combobox3.Text:='test';
end;

The edit box still shows the selected entry in the drop down list, no matter what I do to the text at OnChange.
0
 
LVL 3

Accepted Solution

by:
sfock earned 150 total points
ID: 7994862
well i just tried and saw you are right. Sorry for the bad tip!
the on change event works, if you type a letter, but this is not what you want.
It does also work if you assign it from "out of the List Select"

Anyhow the only surlely working solution i found jet is to place a TEdit over the Combobox EditFiled and assign your related text there ... sorry for now
0
 
LVL 2

Author Comment

by:gsteup
ID: 7996188
Yes, that thought had crossed my mind ones or twice and you are right, it is a workaround.

What I said earlier is still troubling me though. The onChange event gets called and the text property is changed during that.
There must be some other event later on that is reversing this change. Is there a way to trace all the events that happen to the combobox?
Or maybe that is a bug in Delphi that hasn't been adressed yet, who knows...
0
 
LVL 17

Expert Comment

by:geobul
ID: 7996663
Hi,

1. Load the items from the ini file as they are written there:
ComboBox1.Items[x] should be 'power cycle=a5 00 05 50'

2.Set the Style property to csOwnerDrawFixed and write the following OnDrawItem event handler:

procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
begin
  if (Control is TComboBox) then begin
    with (Control as TComboBox) do begin
      Canvas.FillRect(Rect);
      if odComboBoxEdit in State then begin
        Canvas.TextOut(Rect.Left + 2, Rect.Top+2, Items.Values[Items.Names[Index]]);
      end else begin
        Canvas.TextOut(Rect.Left + 2, Rect.Top+2, Items.Names[Index]);
      end;
    end;
  end;
end;

Regards, Geo
0
 
LVL 2

Author Comment

by:gsteup
ID: 7999694
geobul:

Thanks for your solution. It works great, unfortunately I need the edit box to complete or fill in the commands after I select a template out of the list. So it doesn't work for me in this particuar case.

Sfock:

I implemented the overlaying edit box and it work fine. I will exept your comment as an answer.

Thanks everybody!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month15 days, 17 hours left to enroll

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question