一个winform窗体里面有两个窗体Form1和Form2,在Form1中有一个dataGridView控件,通过contextMenuStrip将控件里面的数据传递到Form2中的textBox中,数据库是oracle

解决方案 »

  1.   

    DataGridview单元格双击事件添加一下,方法里面写上
    private void 编辑选中ToolStripMenuItem_Click(object sender, EventArgs e)
            {
                int colIndex = this.ViewAccess.CurrentCell.ColumnIndex;
                string colunmnName = this.ViewAccess.Columns[this.ViewAccess.CurrentCell.ColumnIndex].Name;
                List<int> rowIndex = new List<int>();
                for (int i = ViewAccess.SelectedCells.Count - 1; i >= 0; i--)
                {
                    int c = ViewAccess.SelectedCells[i].RowIndex;
                    TextBox1.Text = ViewAccess.Rows[c].Cells[colunmnName ].ToString();
                }
            }
      

  2.   

    原理是通过获取datagridview选中行对象,然后再获取其中你想要的列的值,后边无论是给文本框还是其他操作就看你的表演了
    dataGridView.SelectedRows[0].Cells["Name"].Value.ToString()