Solved

syncronizing comboboxs

Posted on 1998-10-10
7
217 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

856 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