【发布时间】:2018-06-11 04:23:36
【问题描述】:
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
HResult=0x800703E9
Source=
堆栈跟踪:
更新:
这是组合框中索引更改的事件:
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();
}
这是异常发生的预测方法:
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;
}
}
【问题讨论】:
-
请分享您的代码。没有它,我们无法为您提供帮助。
-
@Mureinik 更新
-
您是否在页面加载时更改索引/绑定?
-
@AlwaysLearning 我正在为页面加载时的所有项目分配一些默认值。但是 cmbxDoortype 的默认索引为 0,当 index 为 1 时会出现此异常,当 index=2 时也可以正常工作。