Solved

syncronizing comboboxs

Posted on 1998-10-10
7
219 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
[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
  • 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
Industry Leaders: 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 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: 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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Intraweb download file link ? 1 184
Delphi Mdi application Child forms get behind control 7 365
Create a path if not exists 7 128
Delphi Seattle StructureView color 1 35
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…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

710 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