Passing Value from One Form to Another (C#)

后端 未结 1 457
时光取名叫无心
时光取名叫无心 2021-01-29 06:45

I have a search form in my program. When the user double-clicks a cell (of the dgv) on the search form, I want the program to close that form and jump to the item on the main fo

相关标签:
1条回答
  • 2021-01-29 06:57

    I suggest you do as follows:

    Search Form:

    public int SelectedId { get; set; }
    
    private void searchdgv_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
    {
        this.rowIndex1 = e.RowIndex;
        this.SelectedId = Convert.ToInt32(this.searchdgv.Rows[this.rowIndex1].Cells["id"].Value);
        this.DialogResult = DialogResult.OK;
        this.Close();
    }
    

    Main form:

    private void searchToolStripMenuItem_Click(object sender, EventArgs e)
    {
        search form1 = new search();
        form1.ShowDialog();
    
        if (form1.DialogResult == DialogResult.OK)
        {
            int selectedId = form1.SelectedId;
            // Do whatever with selectedId...
        }
    
    0 讨论(0)
提交回复
热议问题