我被困在編程問題上。當我右鍵單擊一個DataGridView對象的單元格時,會顯示一個上下文菜單。從該上下文菜單中,用戶可以點擊一個選項。該選項將顯示一個表單。用戶完成後,該表單的結果將填充到所選單元格中。無法從子窗體獲取數據到選定的父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));
}
}
}
有你接過來一看,以http://stackoverflow.com/questions/1516252/如何以編程方式設置單元格值datagridview – tschmit007