如何在winform上显示特定的gridview行数据到另一个winforms组合框

时间:2013-02-02 10:13:36

标签: winforms c#-4.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是一个静态变量,但不能以主窗体形式访问。

任何suugestions ???? 如果你需要更多的探索,我在这里详细说明。

2 个答案:

答案 0 :(得分: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();

答案 1 :(得分:0)

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

  if (frm.DialogResult == System.Windows.Forms.DialogResult.OK)
    {
        var SelectedRecord = frm._SelectedRecord;
    }