以下是任何选定单元格的示例:
表格2:
private string pVal;
//getter and setter
public string PassVal
{
get { return pVal; }
set { pVal = value; }
}
//or event that you need
private void Form2_Load(object sender, EventArgs e)
{
textBox1.Text = pVal;
}
表格1:
Form2 f2 = new Form2();
int selectedCellCount = dataGridView1.GetCellCount(DataGridViewElementStates.Selected);
if (selectedCellCount > 0)
{
for (int i = 0; i < selectedCellCount; i++)
{
int column = dataGridView1.SelectedCells[i].ColumnIndex;
int row = dataGridView1.SelectedCells[i].RowIndex;
f2.PassVal = dataGridView1[column, row].Value.ToString();
}
}
f2.Show();
使用这种和平的代码,您将从文本框中的任何选定单元格中获取文本。
希望它对你有所帮助。