Solved

syncronizing comboboxs

Posted on 1998-10-10
7
216 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Using idhttp to login to instagram 2 90
Multiple image collision 13 75
Find and Replace Stream with 0s 8 62
TEMBEDDEDWB how can i change its user agent ? 8 58
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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

809 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