1 回答
TA贡献1799条经验 获得超6个赞
问题出在StockSearch(模态形式)方面:关闭时StockSearch您应该设置DialogResult:这里有两种可能的关闭方式 -取消(默认行为)和OK。
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) {
selectedStockDescription = dgv_StckSrchRes.Rows[e.RowIndex].Cells[1].Value.ToString();
selectedStockCode = dgv_StckSrchRes.Rows[e.RowIndex].Cells[0].Value.ToString();
DialogResult result = MessageBox.Show(
(selectedStockDescription),
"Add this item to the order?",
MessageBoxButtons.YesNoCancel,
MessageBoxIcon.Question);
if (result == DialogResult.Yes) {
// Confirmed: close the form WITH the choice made (DialogResult.OK)
stockCode = selectedStockCode;
stockDescription = selectedStockDescription;
// this.Close(); // <- cause of the misbehaviour
this.DialogResult = DialogResult.OK; // <- not Close (with cancel) but with OK
}
else if (result == DialogResult.No)
// Not confirmed: keep on selecting
this.Focus();
else // no need in "if": all the rest is Cancel
// Cancellation: close the form WITHOUT choice (DialogResult.Cancel)
this.Close(); // <- Close with DialogResult.Cancel
}
在父窗体端
using (StockSearch ss = new StockSearch(selectedDept, txb_StockCode.Text)) {
if (ss.ShowDialog() != DialogResult.Cancel) {
stckCd = ss.stockCode;
// You should not change stockDescription on DialogResult.Cancel
stockDescription = ss.stockDescription;
}
//TODO: it seems that these three calls should be within if as well
SetFormProperties();
PopulateStockInformation();
GetLeadTimes();
}
- 1 回答
- 0 关注
- 366 浏览
添加回答
举报