In my C# windows form application, there is a combo box that has 3 options in it, when selecting second one a switch command that checks options of another combo box throws and exception of type stack overflow, with this details:
System.StackOverflowException occurred
HResult=0x800703E9
Source=<Cannot evaluate the exception source>
StackTrace:
<Cannot evaluate the exception stack trace>
Update:
this is the event of index change in combo box:
private void cmbxDoorType_SelectedIndexChanged(object sender, EventArgs e)
{
if (cmbxDoorType.SelectedIndex == 0)
{
chkTopBlock.Enabled = true;
if(chkTopBlock.Checked)
cmbxTopBlockConfig.Enabled = true;
cmbxTopSideConfig.Enabled = true;
txtDoorHeight.ReadOnly = false;
txtTotalWidth.Visible = false;
lblTotalWidth.Visible = false;
lblDoorBaleWidth.Enabled = false;
}
else if (cmbxDoorType.SelectedIndex == 1)
{
txtTotalWidth.Visible = false;
lblTotalWidth.Visible = false;
lblDoorBaleWidth.Enabled = false;
cmbxTopBlockConfig.Enabled = false;
chkTopBlock.Enabled = false;
txtDoorHeight.ReadOnly = true;
cmbxTopSideConfig.Enabled = false;
}
else
{
chkTopBlock.Enabled = true;
if (chkTopBlock.Checked)
cmbxTopBlockConfig.Enabled = true;
cmbxTopSideConfig.Enabled = true;
txtDoorHeight.ReadOnly = false;
txtTotalWidth.Visible = true;
lblTotalWidth.Visible = true;
lblDoorBaleWidth.Enabled = true;
}
Prediction();
}
this is the prediction methode than exception ocours in:
internal void Prediction ()
{
if (Globals.ProjectType=="Gama")
{
int TotalHeight_=0;
double DesignHeight_=0;
int TotalWidth_=0;
double LeftDis = 0;
double RightDis = 0;
double RowsTotalHeight_=0;
double TopBlockHeight_=0;
double thisDoorHeight_ = 0;
int DoorHeight_=0;
int DoorWidth_=0;
double DoorBaleWidth_=0;
try
{
switch (cmbxLeftSideConfig.SelectedIndex) //exception thrown here
{
case 0:
LeftDis = GamaGlobals.Constants.BeamThickness - GamaGlobals.Constants.InsertOffset;
break;
case 2:
LeftDis = GamaGlobals.Constants.GP115Body + GamaGlobals.Constants.BeamThickness - GamaGlobals.Constants.InsertOffset;
break;
case 3:
LeftDis = GamaGlobals.Constants.GP114Body + GamaGlobals.Constants.BeamThickness - GamaGlobals.Constants.InsertOffset;
break;
case 4:
LeftDis = GamaGlobals.Constants.GP117Height - GamaGlobals.Constants.InsertOffset;
break;
case 1:
LeftDis = 0;
break;
}
switch (cmbxRightSideConfig.SelectedIndex)
{
case 0:
RightDis = GamaGlobals.Constants.BeamThickness - GamaGlobals.Constants.InsertOffset;
break;
case 2:
RightDis = GamaGlobals.Constants.GP115Body + GamaGlobals.Constants.BeamThickness - GamaGlobals.Constants.InsertOffset;
break;
case 3:
RightDis = GamaGlobals.Constants.GP114Body + GamaGlobals.Constants.BeamThickness - GamaGlobals.Constants.InsertOffset;
break;
case 4:
RightDis = GamaGlobals.Constants.GP117Height - GamaGlobals.Constants.InsertOffset;
break;
case 1:
RightDis = 0;
break;
}
}
Something in your cmbxDoorType_SelectedIndexChanged
, or another SelectedIndexChanged
event will retrigger your event again, which makes it a StackOverFlowException
after a couple of seconds
in "prediction" method there was a line that changes a textbox value, and that text box itself has a value changed event that triggers "prediction" again.
so it's solved.
just as another question, is there a way to change textbox/numericupdown controls value programmatically without triggering its change event? for example, if the user changes it, it triggers event but when its programmatically changed, the event does not trigger. hm??
User contributions licensed under CC BY-SA 3.0