我被编程问题困扰了。当我右键单击DataGridView对象的单元格时,将显示上下文菜单。从该上下文菜单中,用户可以单击选项。该选项将显示一个表单。用户完成后,将在所选单元格中填充该表单的结果。
问题:如何将子表单的结果导入所选单元格?父表单上有多个使用相同功能的DataGridView对象。
代码:
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));
}
}
}
答案 0 :(得分:0)
一种非常简单的方法是在弹出窗口中放置一个公共属性,它将返回您想要的值(Say RtnValue)。然后
这是弹出窗体的示例:
public string RtnValue
{
set { textBox1.Text = value; }
}
这是您当前的代码:
frmNumFormatConv form = new frmNumFormatConv();
if (form.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
dgvalue = form.RtnValue;
// Get data from the form into the selected cell!!!
}