1
votes

I have been stumped on a programming issue. When I right click on a cell of a DataGridView object, a context menu will show. From that context menu, a user can click an option. That option will show a form. When the user is finished, the resultant of that form will be populated in the selected cell.

Problem: How do I get the result from the child form into the selected cell? There are multiple DataGridView objects on the parent form that use the same functionality.

Code:

    private void commandOperation(Object sender, EventArgs e)
    {
        if (sender == dec2HexToolStripMenuItem)
        {
            frmNumFormatConv form = new frmNumFormatConv();
            if (form.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                // Get data from the form into the selected cell!!!
            }
        }
        else
        {
            throw new Exception("Operational object unknown");
        }
    }

    private void cellMouseDown(Object sender, DataGridViewCellMouseEventArgs e)
    {
        if (sender == dgvCircuit1TestSetup || sender == dgvCircuit2TestSetup)
        {
            if (e.Button == MouseButtons.Right)
            {
                ((DataGridView)sender).CurrentCell = ((DataGridView)sender).Rows[e.RowIndex].Cells[e.ColumnIndex];
                itsGridContextMenu.Show((DataGridView)sender, new Point(e.X, e.Y));
            }
        }
    }
1

1 Answers

0
votes

A very easy way is to put a public property in the popup form that will return the values you want (Say RtnValue). Then

This is an example for popup form:

    public string RtnValue
    {
        set { textBox1.Text = value; }
    }

This is your current code:

frmNumFormatConv form = new frmNumFormatConv();
        if (form.ShowDialog() == System.Windows.Forms.DialogResult.OK)
        {
            dgvalue = form.RtnValue;
            // Get data from the form into the selected cell!!!
        }