Solved

syncronizing comboboxs

Posted on 1998-10-10
7
212 Views
Last Modified: 2010-04-06
Hello,
I have 6 combobox each with 15 lines.
when a user selects line 4 (for example) how do i make
the other 5 comboboxs display their line 4's as well
thankyou for your assistance.
0
Comment
Question by:inthe
  • 4
  • 2
7 Comments
 
LVL 5

Accepted Solution

by:
scrapdog earned 100 total points
ID: 1342511
In the OnChange event for each of your combo boxes:


procedure TForm1.ComboBox1Change(Sender: TObject);
var x :integer;
begin
  x := ComboBox1.ItemIndex;
  ComboBox2.ItemIndex := x;
  ComboBox3.ItemIndex := x;
  ComboBox4.ItemIndex := x;
  ComboBox5.ItemIndex := x;
  ComboBox6.ItemIndex := x;
end;

You would have to do this for each of your combo boxes.  For example, combo box 2 would look like this:

procedure TForm1.ComboBox2Change(Sender: TObject);
var x :integer;
begin
  x := ComboBox2.ItemIndex;
  ComboBox1.ItemIndex := x;
  ComboBox3.ItemIndex := x;
  ComboBox4.ItemIndex := x;
  ComboBox5.ItemIndex := x;
  ComboBox6.ItemIndex := x;
end;


Of course, there are other ways to do this, but this is the simplest.

0
 
LVL 10

Expert Comment

by:viktornet
ID: 1342512
Here is something that you might want to try as well.......

procedure TForm1.ComboBox1Change(Sender: TObject);
var
  x, i :integer;
begin
  if Sender is TComboBox then begin //You could do it w/o this line, but better be sure than sorry
    x := TComboBox(Sender).ItemIndex;
    for i := 0 to ComponentCount - 1 do
      if Components[i] is TComboBox then
        Components[i].ItemIndex := x;
  end;
end;

Just put this in each of the ComboBoxes' OnChange() event and try it if it works.... I haven't tested this but is suppose to be working :-) Talk to ya later ;->

Regards,
Viktor Ivanov
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1342513
Ok, just tried it on and it works... I had to change a little, but here is the new code that works...

procedure TForm1.ComboBox1Change(Sender: TObject);
var
  x, i :integer;
begin
  if Sender is TComboBox then begin
    x := TComboBox(Sender).ItemIndex;
    for i := 0 to ComponentCount - 1 do
      if Components[i] is TComboBox then
        TComboBox(Components[i]).ItemIndex := x; //I changed this one a little...
  end;
end;

Note: What I mean by put this code in each of the ComboBoxes' OnChange() is that you just put the code in one of the ComboBoxes' OnChange() and then assign the same OnChange() ot the rest of the ComboBoxes' OnChange()

Here is an example of what I just said....
let's say you assigned the code the the OnChange() of a ComboBox whose name is ComboBox1--->
procedure TForm1.ComboBox1Change(Sender: TObject);
{..Code follows here...}
Then you got to the object inspector and go to the events Page of the object Inspector... YOu either select all the ComboBoxes at the same time and Assign the OnChange of the comboboxes' to the ComboBox1Change, or you could go through each of them and assign it one by one... If all this makes no sense just tell me and I'll send you a demo app...

Regards,
Viktor Ivanov
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 17

Author Comment

by:inthe
ID: 1342514
thankyou to scrapdog and viktor
i really cant believe i never thought of the first one
as ive done something nearly identical 7 lines done the page!
oh well thanks again
0
 
LVL 5

Expert Comment

by:scrapdog
ID: 1342515
Viktor's method will work equally well, as long as the 6 combo boxes you want to change are the only ones on the form (I did not assume this.)
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1342516
Ok, here is exactly what you need ;->

function ChkNme(Comp : TComponent):boolean;
begin
      Result := False;
      if ((Comp.Name = 'ComboBox1')or(Comp.Name = 'ComboBox2')or(Comp.Name = 'ComboBox3')
   or(Comp.Name = 'ComboBox4')or(Comp.Name = 'ComboBox5')or(Comp.Name = 'ComboBox6'))then
         Result := True;
end;

procedure TForm1.ComboBox1Change(Sender: TObject);
     var
       x, i :integer;
     begin
       if Sender is TComboBox then begin
         x := TComboBox(Sender).ItemIndex;
         for i := 0 to ComponentCount - 1 do
           if Components[i] is TComboBox then
             if ChkNme(Components[i]) then
                   TComboBox(Components[i]).ItemIndex := x;
       end;
     end;

Hope this helps.... Out the code of the OnChange() only in the ComboBoxes that need to be changed...It will check if the name is in the list and then if it's not the procedure won't change the ItemIndex of the ComboBoxes whose name is not in the list....

Regards,
Viktor Ivanov
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1342517
Out = Put
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now