如何获取单击的单元格的值并将其传输到第二个表单?
到目前为止,这是我的代码:
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 1)
{
var form2 = new Form2();
this.Hide();
form2.Show();
}
}
答案 0 :(得分:1)
更改将接收值的表单的构造函数,如:
public Form2(String passCellValue)
{
InitializeComponent();
}
然后这样打电话:
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 1)
{
String cellValue;
cellValue = dataGridView1[e.ColumnIndex, e.RowIndex].Value.ToString();
var form2 = new Form2(cellValue);
this.Hide();
form2.Show();
}
}
答案 1 :(得分:0)
很容易
private void gridAgentDetails_Click(object sender, EventArgs e) { for (int i = 0; i < this.gridAgentDetails.CurrentRowIndex; i++) { string str = gridAgentDetails.Text; }}
plaese检查链接
How to get column value of grid in C# Windows application?
并传输数据,您可以制作一般属性或变量。请检查此链接。