Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 12-11-2014, 03:16 AM
Badger Badger is offline
Member
 
Join Date: Aug 2013
Location: Sheffield, Tasmania (Aust)
Posts: 76
Default Updating combo box output at run time

In my program I change a Combobox items at run time and want the output in the combo box to reflect this if that particular item is selected. I.E. if the combo box has the first item selected and this is President then the first item is changed to Chairman I want the Combo box to show Chairman. It works OK but you have to open and close the combobox to get the output to change.

I tried using the code given in a previos thread but when I try to compile it I get an error - it doesn't recognise .Perform (running under FMX)

Code:
 
Procedure TCommitteeStructureForm.Update(NewName:String);
var
  x:integer;
begin
  if NewName<>'' then
  begin
    for x:=0 to CommitteeNumber-1 do
    begin
      ComboArray[x].Items[0]:=NewName;
      ComboArray[x].Items[1]:='Vice-'+NewName;
      ......
      ComboArray[x].Perform(WM_KEYDOWN,VK_DOWN,0);
      ComboArray[x].Perform(WM_KEYDOWN,VK_Up,0);
    end;
  end;
end;
Regards

Badger
Reply With Quote
  #2  
Old 12-11-2014, 05:11 AM
Jasser Jasser is offline
Moderator
 
Join Date: Jan 2005
Location: Saudi Arabia
Posts: 5,059
Default

Try to "Refresh" method of TCombobox.

Code:
Combobox1.Refresh;
__________________
Regards,
Abdulaziz Jasser
Reply With Quote
  #3  
Old 12-11-2014, 07:12 AM
kolbasz kolbasz is offline
Senior Member
 
Join Date: Nov 2013
Posts: 841
Default

Here you go:
Code:
var
  x: Integer;
  Selected: Integer;
begin
  if NewName = '' then
    Exit;
  for x := 0 to CommitteeNumber - 1 do
  begin
    Selected := ComboArray[x].ItemIndex;
    ComboArray[x].Items.BeginUpdate;
    try
      ComboArray[x].Items[0] := NewName;
      ComboArray[x].Items[1] := 'Vice-' + NewName;
      //...
      if (Selected <> -1) and (Selected <= ComboArray[x].Items.Count - 1) then     
        ComboArray[x].ItemIndex := Selected;            
    finally
      ComboArray[x].Items.EndUpdate;
    end;
    ComboArray[x].Repaint;
  end;
end;
Reply With Quote
  #4  
Old 12-12-2014, 09:27 AM
Badger Badger is offline
Member
 
Join Date: Aug 2013
Location: Sheffield, Tasmania (Aust)
Posts: 76
Default

Jassar 0, Kolbasz 1.
I tried both. Jasar's wouldn't compile, it got me E2003 Undeclared Identifier 'refresh'. Kolbasz version ran OK.

However, I also got it to work simply by adding the ComboArray[x].Repaint; to my code. Easy!!

Thanks Guys
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 01:46 AM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.