Click here to Skip to main content
15,888,984 members
Please Sign up or sign in to vote.
2.33/5 (3 votes)
See more:
I have three DataGridViewComboBoxColumn in my DataGridView. Based on the values selected in these column, I need to set values to the gridcells.

While doing so if the user clicks the DataGridViewComboBoxColumn more than once, I am getting stackoverflow error

C#
private void drvRtn_EditingControlShowing(object sender,DataGridViewEditingControlShowingEventArgs e) 
{ 
     if (drvRtn.CurrentCell.ColumnIndex == 21) 
    { 
       ComboBox comboBox = e.Control as ComboBox; comboBox.SelectedIndexChanged += new EventHandler(comboBox_SelectedIndexChanged); 
     } 
} 

void comboBox_SelectedIndexChanged(object sender, EventArgs e) 
{ 
     if (drvRtn.CurrentCell.ColumnIndex == 21 ) 
     { 
         int selectedIndex = ((ComboBox)sender).SelectedIndex; if (selectedIndex == 0) 
         { 
             DateTime time1 = DateTime.Now; 
             time1 = DateTime.Now; 
             drvRtn[22, 0].Value = "CONTACTABLE-NO ADD CHANGE" ;
              drvRtn[21, 0].Value = "CONTACTABLE-NO ADD CHANGE" ;
              string format = "HH:mm:ss"; 
               drvRtn[19, 0].Value = time1.ToString(format); 
              drvRtn[18, 0].Value = time1.ToString(); 
              drvRtn[23, 0].Value = time1.ToString(); 
        } 
     }
}


private void drvRtn_CellClick_1(object sender, DataGridViewCellEventArgs e) 
{ 
    columnIndex = drvRtn.CurrentCell.ColumnIndex; if (columnIndex == 17) 
    { 
        DataGridViewComboBoxColumn colRtnRsn = new DataGridViewComboBoxColumn(); 
        colRtnRsn.Items.AddRange("NONE", "SELF", "HUSBAND", "MOTHER", "FATHER", "SISTER"); 
        //colRtnRsn.DataPropertyName = "spoke_to1"; 
        //  colRtnRsn.ValueMember = "spoke_to1"; 
        //  colRtnRsn.DisplayMember = "spoke_to1"; 
        //  colRtnRsn.HeaderText = "spoke_to1"; 
         // colRtnRsn.Width = 120; 
       //colRtnRsn.AutoSizeMode = DataGridViewAutoSizeColumnMode.NotSet; 
       if (Ctr2 == 0) 
       { this.drvRtn.Columns.Remove("spoke_to1"); 
         this.drvRtn.Columns.Insert(17, colRtnRsn); 
         Ctr2 = Ctr2 + 1; 
       }
    } 
}


Any solution to this issue will be highly appreciated.

Regards

Edward
Posted
v5
Comments
Menon Santosh 27-Jul-12 8:53am    
plz post the error
[no name] 27-Jul-12 9:02am    
You need to post your code.
Member 7953139 27-Jul-12 9:07am    
An unhandled exception of type 'System.StackOverflowException' occurred in System.Windows.Forms.dll
fjdiewornncalwe 27-Jul-12 9:17am    
Could you include the stack trace and a snippet of your code (the onclick code for teh DataGridViewComboBoxColumn). Use the Improve Question widget to update your question with this information.
Member 7953139 27-Jul-12 9:19am    
private void drvRtn_EditingControlShowing(object sender,DataGridViewEditingControlShowingEventArgs e)
{
if (drvRtn.CurrentCell.ColumnIndex == 21)
{
ComboBox comboBox = e.Control as ComboBox;
comboBox.SelectedIndexChanged += new EventHandler(comboBox_SelectedIndexChanged);

}
}


void comboBox_SelectedIndexChanged(object sender, EventArgs e)
{
if (drvRtn.CurrentCell.ColumnIndex == 21 )
{
int selectedIndex = ((ComboBox)sender).SelectedIndex;
if (selectedIndex == 0)
{
DateTime time1 = DateTime.Now;
time1 = DateTime.Now;

drvRtn[22, 0].Value = "CONTACTABLE-NO ADD CHANGE""
drvRtn[21, 0].Value = "CONTACTABLE-NO ADD CHANGE""


string format = "HH:mm:ss;
drvRtn[19, 0].Value = time1.ToString(format);
drvRtn[18, 0].Value = time1.ToString();
drvRtn[23, 0].Value = time1.ToString();

}

}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900