【发布时间】:2013-11-26 10:52:11
【问题描述】:
简而言之,我想返回上一个选定项而不再次选择它或不触发 SelectedIndexChanged 方法。
情况是这样的:我有组合框,当一个项目被选中时,datagridview 被行填充。您可以在 datagridview 中编辑内容并将它们保存到文件中。如果您不保存更改并尝试更改组合框中的项目,它会告诉您所有更改都将丢失。我制作了一个消息框,让您在是(更改)和否(不更改)之间进行选择。如果单击“是”,则一切正常,但如果单击“否”,则我必须返回先前选择的项目。当我这样做时,我会触发 SelectedIndexChanged,这会使 datagridview 再次加载并删除更改。这是我在 SelectedIndexChanged 方法中的代码:
if (!ChangeMade)
{
//#1 Some Code
}
else
{
DialogResult dialogResult =
MessageBox.Show("Are you sure you want to change the manifacturer?" +
"\n All the changes you have done will be lost.",
"Warning", MessageBoxButtons.YesNo);
if (dialogResult == DialogResult.Yes)
{
//same code as #1
}
else
{
//Here must be the code that returns the previous
//item without selecting it.
}
对不起我的英语。
【问题讨论】: