Click here to Skip to main content
16,004,919 members
Home / Discussions / C#
   

C#

 
GeneralRe: Presentation Help..... Pin
AmbiguousName18-May-10 7:44
AmbiguousName18-May-10 7:44 
GeneralRe: Presentation Help..... Pin
OriginalGriff18-May-10 8:11
mveOriginalGriff18-May-10 8:11 
AnswerRe: Presentation Help..... Pin
Christo66718-May-10 23:57
Christo66718-May-10 23:57 
QuestionComboBox selection generating list for another comboBox question Pin
mprice21418-May-10 6:24
mprice21418-May-10 6:24 
AnswerRe: ComboBox selection generating list for another comboBox question Pin
William Winner18-May-10 7:18
William Winner18-May-10 7:18 
AnswerRe: ComboBox selection generating list for another comboBox question Pin
Henry Minute18-May-10 7:23
Henry Minute18-May-10 7:23 
GeneralRe: ComboBox selection generating list for another comboBox question Pin
mprice21418-May-10 8:18
mprice21418-May-10 8:18 
GeneralRe: ComboBox selection generating list for another comboBox question [modified] Pin
Henry Minute18-May-10 8:40
Henry Minute18-May-10 8:40 
This is how to get the SelectedIndexChanged event handler hooked up properly. Handle the EditingControlShowing event of your DataGridView. It's rather nifty.

private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
    ComboBox cb = e.Control as ComboBox;

    if (cb != null)
    {
        // first remove event handler to keep from attaching multiple:
        cb.SelectedIndexChanged -= cb_SelectedIndexChanged;
        // now attach the event handler
        cb.SelectedIndexChanged += cb_SelectedIndexChanged;
    }
}



void cb_SelectedIndexChanged(object sender, EventArgs e)
{
    MessageBox.Show("Selected index changed");
}


Simply substitute the correct control names/indexes to suit your application.

Good luck! Smile | :)

[Edit]
You can refine this slightly to enable handling SelectedIndexChanged events for more than one ComboBoxColumn.

private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
   ComboBox cb;

   switch (dataGrid.CurrentCell.ColumnIndex)
   {
       case 0:  // use the index for your comboboxcolumn
           cb = e.Control as ComboBox;
           if (cb != null)
           {
           // first remove event handler to keep from attaching multiple:
           cb.SelectedIndexChanged -= cb_SelectedIndexChanged;
           // now attach the event handler
           cb.SelectedIndexChanged += cb_SelectedIndexChanged;
           }
           break;
      case 3: // use the index for your second combo
           cb = e.Control as ComboBox;
           if (cb != null)
           {
           // first remove event handler to keep from attaching multiple:
           cb.SelectedIndexChanged -= cb_SecondSelectedIndexChanged;
           // now attach the event handler
           cb.SelectedIndexChanged += cb_SecondSelectedIndexChanged;
           }
           break;
   }

[/Edit]

Hope this helps. Smile | :)
Henry Minute

Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
Why do programmers often confuse Halloween and Christmas?
Because 31 Oct = 25 Dec.
modified on Tuesday, May 18, 2010 2:53 PM

GeneralRe: ComboBox selection generating list for another comboBox question Pin
mprice21418-May-10 10:43
mprice21418-May-10 10:43 
GeneralRe: ComboBox selection generating list for another comboBox question Pin
Henry Minute18-May-10 11:43
Henry Minute18-May-10 11:43 
GeneralRe: ComboBox selection generating list for another comboBox question Pin
mprice21418-May-10 12:10
mprice21418-May-10 12:10 
GeneralRe: ComboBox selection generating list for another comboBox question Pin
mprice21418-May-10 17:29
mprice21418-May-10 17:29 
GeneralRe: ComboBox selection generating list for another comboBox question Pin
Henry Minute19-May-10 1:15
Henry Minute19-May-10 1:15 
GeneralRe: ComboBox selection generating list for another comboBox question Pin
mprice21419-May-10 3:49
mprice21419-May-10 3:49 
GeneralRe: ComboBox selection generating list for another comboBox question [modified] Pin
Henry Minute19-May-10 4:22
Henry Minute19-May-10 4:22 
GeneralRe: ComboBox selection generating list for another comboBox question Pin
mprice21419-May-10 4:43
mprice21419-May-10 4:43 
GeneralRe: ComboBox selection generating list for another comboBox question Pin
Henry Minute19-May-10 5:07
Henry Minute19-May-10 5:07 
GeneralRe: ComboBox selection generating list for another comboBox question Pin
mprice21419-May-10 5:29
mprice21419-May-10 5:29 
GeneralRe: ComboBox selection generating list for another comboBox question Pin
mprice21419-May-10 18:46
mprice21419-May-10 18:46 
GeneralRe: ComboBox selection generating list for another comboBox question Pin
Henry Minute20-May-10 1:35
Henry Minute20-May-10 1:35 
GeneralRe: ComboBox selection generating list for another comboBox question [modified] Pin
mprice21420-May-10 3:44
mprice21420-May-10 3:44 
GeneralRe: ComboBox selection generating list for another comboBox question Pin
Henry Minute20-May-10 5:23
Henry Minute20-May-10 5:23 
GeneralRe: ComboBox selection generating list for another comboBox question Pin
mprice21426-May-10 19:10
mprice21426-May-10 19:10 
AnswerRe: ComboBox selection generating list for another comboBox question Pin
William Winner18-May-10 7:31
William Winner18-May-10 7:31 
GeneralRe: ComboBox selection generating list for another comboBox question Pin
mprice21418-May-10 7:58
mprice21418-May-10 7:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.