Solved

syncronizing comboboxs

Posted on 1998-10-10
7
213 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
creating manifest for my dll that called from activex 6 99
Newbie Thread Programming 1 139
Using idhttp to login to instagram 2 76
Find and Replace Stream with 0s 8 57
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

920 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

14 Experts available now in Live!

Get 1:1 Help Now