获取单元格的值并将其转换为第二种形式
本文关键字:二种 单元格 转换 获取 | 更新日期: 2024-09-21 15:24:10
如何获取单击的单元格的值并将其转移到第二个表单上?
这是我迄今为止的代码:
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 1)
{
var form2 = new Form2();
this.Hide();
form2.Show();
}
}
更改将接收值的窗体的构造函数,如:
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();
}
}
它非常容易
private void gridAgentDetails_Click(object sender, EventArgs e) { for (int i = 0; i < this.gridAgentDetails.CurrentRowIndex; i++) { string str = gridAgentDetails.Text; }}
plaese检查链接
如何在C#Windows应用程序中获取网格的列值?
为了传输数据,您可以制作通用属性或变量。请检查此链接。
http://social.msdn.microsoft.com/Forums/vstudio/en-US/08943b7b-9603-49ad-950c-62e8f8325df2/how-to-pass-value-data-grid-view-click-to-another-form?forum=vbgeneral