0

我正在使用 win 表单来搜索记录,并且当从 celldoubleclick 事件的网格中选择记录时。应关闭搜索表单,并将选定的行记录加载回主表单,从中开始调用搜索表单。

打开搜索表单的代码。

private void F1Button_Click(object sender, EventArgs e)
    {
        Forms.frmSearchNewAccount frm = new Forms.frmSearchNewAccount();
        frm.ShowDialog();
        if (frm.DialogResult == System.Windows.Forms.DialogResult.OK)
        {
            //here comes the selected record
        }
    }

//搜索表单网格视图单元格双击事件代码在这里

try
        {
            if (e.RowIndex >= 0)
            {
                this._SelectedRecord = new Flour_Mills.PARTY();
                _SelectedRecord.PARTY_ID = (string)((DataTable)SearchPartydataGrid.DataSource).Rows[e.RowIndex]["PARTY_ID"];
                _SelectedRecord.NAME = (string)((DataTable)SearchPartydataGrid.DataSource).Rows[e.RowIndex]["NAME"];
                Controller.PartyDAL.Load(_SelectedRecord.PARTY_ID);
                DialogResult = System.Windows.Forms.DialogResult.OK;
                this.Close();
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }

_selectedRecord 是一个静态变量,但在主窗体中不可访问。

有什么建议吗???如果您需要更多解释,我会在这里详细说明。

4

2 回答 2

0

简单地说,它可以这样做:

public var _selectedRecordFromSearchForm;

private void F1Button_Click(object sender, EventArgs e)
{
    Forms.frmSearchNewAccount frm = new Forms.frmSearchNewAccount();
    frm.ShowDialog(this); // pass this form as Owner
    if (frm.DialogResult == System.Windows.Forms.DialogResult.OK)
    {
        //here comes the selected record
    }
}

在搜索表格中:

this._SelectedRecord = new Flour_Mills.PARTY();
_SelectedRecord.PARTY_ID = (string)((DataTable)SearchPartydataGrid.DataSource).Rows[e.RowIndex]["PARTY_ID"];
_SelectedRecord.NAME = (string)((DataTable)SearchPartydataGrid.DataSource).Rows[e.RowIndex]["NAME"];
Controller.PartyDAL.Load(_SelectedRecord.PARTY_ID);
this.Owner._selectedRecordFromSearchForm = _SelectedRecord;  // set _searchRecoed to owners field
DialogResult = System.Windows.Forms.DialogResult.OK;
this.Close();
于 2013-02-02T10:20:30.640 回答
0

您可以在搜索表单中声明_SelectedRecord为公开,当表单关闭时,您可以像这样访问变量:

  if (frm.DialogResult == System.Windows.Forms.DialogResult.OK)
    {
        var SelectedRecord = frm._SelectedRecord;
    }
于 2013-02-02T11:57:33.473 回答