Sync ComboBox : ComboBox « GUI Form « Visual C++ .NET

Home
Visual C++ .NET
1.2D
2.Class
3.Collections
4.Data Type
5.Database ADO.net
6.Delegate
7.Development
8.File Directory
9.Function
10.Generics
11.GUI Form
12.Language Basics
13.Network
14.Reflection
15.Security
16.Statement
17.Structure
18.Thread
19.XML
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Visual C++ .NET » GUI Form » ComboBox 
Sync ComboBox
 

  using namespace System;
  using namespace System::ComponentModel;
  using namespace System::Collections;
  using namespace System::Windows::Forms;
  using namespace System::Data;
  using namespace System::Drawing;

  public ref class Form1 : public System::Windows::Forms::Form
  {
  public:
    Form1(void)
    {
      InitializeComponent();
            PopulateLists();
    }
        System::Windows::Forms::ComboBox^  ddlist;
        System::Windows::Forms::ComboBox^  simple;
        System::Windows::Forms::ComboBox^  ddown;

    void InitializeComponent(void)
    {
            this->ddlist = (gcnew System::Windows::Forms::ComboBox());
            this->simple = (gcnew System::Windows::Forms::ComboBox());
            this->ddown = (gcnew System::Windows::Forms::ComboBox());
            this->SuspendLayout();
            // 
            // ddlist
            // 
            this->ddlist->DropDownStyle = 
                System::Windows::Forms::ComboBoxStyle::DropDownList;
            this->ddlist->FormattingEnabled = true;
            this->ddlist->Location = System::Drawing::Point(30014);
            this->ddlist->Name = L"ddlist";
            this->ddlist->Size = System::Drawing::Size(12121);
            this->ddlist->TabIndex = 5;
            this->ddlist->SelectedIndexChanged += 
                gcnew System::EventHandler(this, &Form1::ddlist_Change);
            // 
            // simple
            // 
            this->simple->DropDownStyle = 
                System::Windows::Forms::ComboBoxStyle::Simple;
            this->simple->FormattingEnabled = true;
            this->simple->Location = System::Drawing::Point(15411);
            this->simple->Name = L"simple";
            this->simple->Size = System::Drawing::Size(122117);
            this->simple->TabIndex = 4;
            this->simple->SelectedIndexChanged += 
                gcnew System::EventHandler(this, &Form1::simple_Change);
            this->simple->TextChanged += 
                gcnew System::EventHandler(this, &Form1::simple_Change);
            // 
            // ddown
            // 
            this->ddown->FormattingEnabled = true;
            this->ddown->Location = System::Drawing::Point(1214);
            this->ddown->MaxDropDownItems = 3;
            this->ddown->MaxLength = 10;
            this->ddown->Name = L"ddown";
            this->ddown->Size = System::Drawing::Size(12121);
            this->ddown->TabIndex = 3;
            this->ddown->SelectedIndexChanged += 
                gcnew System::EventHandler(this, &Form1::ddown_Change);

            this->ddown->TextChanged += 
                gcnew System::EventHandler(this, &Form1::ddown_Change);
            // 
            // Form1
            // 
            this->AutoScaleDimensions = System::Drawing::SizeF(613);
            this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
            this->ClientSize = System::Drawing::Size(433138);
            this->Controls->Add(this->ddlist);
            this->Controls->Add(this->simple);
            this->Controls->Add(this->ddown);
            this->Name = L"Form1";
            this->Text = L"Synchronized Combo boxing";
            this->ResumeLayout(false);
    }

        void PopulateLists()
        {
            // Item to be placed in all ComboBoxes
            array<Object^>^ ddItems = gcnew array<Object^> 
                L"oranges", L"cherries", L"apples",
                L"lemons",  L"bananas",  L"grapes" 
            };
            ddown->Items->AddRange(ddItems);        
            simple->Items->AddRange(ddItems);        
            ddlist->Items->AddRange(ddItems);
        }

        System::Void ddown_Change(System::Object^ sender, System::EventArgs^ e)
        {
            // Update simple and dropdownlist with dropdown text
            simple->Text = ddown->Text; 
            ddlist->SelectedItem = ddown->Text; 
        }

        System::Void simple_Change(System::Object^ sender,System::EventArgs^ e)
        {
            // Update dropdown and dropdownlist with simple text
            ddown->Text = simple->Text; 
            ddlist->SelectedItem = simple->Text; 
        }

        System::Void ddlist_Change(System::Object^ sender,System::EventArgs^ e)
        {
            // Update simple and dropdown with dropdownlist SelectedText
            ddown->SelectedItem = ddlist->SelectedItem; 
            simple->SelectedItem = ddlist->SelectedItem; 
        }
  };

[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
  Application::Run(gcnew Form1());
  return 0;
}

   
  
Related examples in the same category
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.