[英]Unable to get data from child form into selected Parent DataGridView Cell
我在编程问题上感到困惑。 当我右键单击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));
}
}
}
一种非常简单的方法是在弹出窗体中放置一个公共属性,该属性将返回所需的值(说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!!!
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.