【发布时间】:2014-07-17 15:58:33
【问题描述】:
我被一个编程问题难住了。当我右键单击 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));
}
}
}
【问题讨论】:
标签: c# datagridview contextmenu