Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > DataGridView Combo box Problem
 

DataGridView Combo box Problem

Hello

i am using a DataGridView in which i have two unbound DataGrid ComboBox Columns. I bound data in these at run time and each combo box contains data from diffrent dataTables.

Now i want to call funtions when some thing changes in Combo Boxes.

I am giving a detail example.

Suppose my table contains two rows first row contains User, and the second row contains State. I populated User row comboo boxes with UserDataTable and State row combo box with StateDataTable which belongs to same data set.

Now what i want that, when some one changes something in UserCombo Box then UserchangesFunction or event should fire
and if some one changes in StateCombo box then StateChangesFuntion or event should fire..


Please provide me a idea how to do this...
Progress2007  Saturday, October 11, 2008 8:15 AM

You can handle the OnIndexChanged event of the ComboBox. Therefore you need to add your personal eventhandler in the EditingControlShowing event of the DGV. Then when something changes, you function gets called.

I think there is an example in the FAQ in this forum.

Code Snippet

private: System::Void dataGridViewComponents_EditingControlShowing(System::Object^ sender, System::Windows::Forms::DataGridViewEditingControlShowingEventArgs^ e) {

if ( dataGridViewComponents->Columns[ dataGridViewComponents->CurrentCell->ColumnIndex ]->Name->Equals( "Component" ) ) {

ComboBox ^cb = dynamic_cast<ComboBox^>(e->Control);

if (cb!=nullptr) {

cb->SelectedIndexChanged -= gcnew System::EventHandler(this, &ApplicationForm::ComboBoxComponent_SelectedIndexChanged);

cb->SelectedIndexChanged += gcnew System::EventHandler(this, &ApplicationForm::ComboBoxComponent_SelectedIndexChanged);

}

}

}

Bernd

wannabe_2  Saturday, October 11, 2008 10:25 PM

You can handle the OnIndexChanged event of the ComboBox. Therefore you need to add your personal eventhandler in the EditingControlShowing event of the DGV. Then when something changes, you function gets called.

I think there is an example in the FAQ in this forum.

Code Snippet

private: System::Void dataGridViewComponents_EditingControlShowing(System::Object^ sender, System::Windows::Forms::DataGridViewEditingControlShowingEventArgs^ e) {

if ( dataGridViewComponents->Columns[ dataGridViewComponents->CurrentCell->ColumnIndex ]->Name->Equals( "Component" ) ) {

ComboBox ^cb = dynamic_cast<ComboBox^>(e->Control);

if (cb!=nullptr) {

cb->SelectedIndexChanged -= gcnew System::EventHandler(this, &ApplicationForm::ComboBoxComponent_SelectedIndexChanged);

cb->SelectedIndexChanged += gcnew System::EventHandler(this, &ApplicationForm::ComboBoxComponent_SelectedIndexChanged);

}

}

}

Bernd

wannabe_2  Saturday, October 11, 2008 10:25 PM

You can use google to search for other answers

Custom Search

More Threads

• How to bind an arraylist to combobox without a nullvaule
• Performance issues when iterating throug DataGridView.SelectedCells
• How do I do dragdrop with left mouse button in Datagridview?
• Rows in the DataGrid automatically deleted
• Last Column AutoSize Fill Mode
• Case-insensitivity for individual columns in a datatable query
• DataGridView OnColumnAdded Event - no suitable method found to override Exception
• R:Base - is there any place for .NET in it?
• Dataset Precision and Scale for Decimal datatype
• Very noob Question about DataGridView toolbox function