在以前的表格中选择身份证号码时,是否可以向其他表格显示其他详细信息?
,这是part of my code
,只要点击该行,它就显示在文本框中:
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex >= 0)
{
DataGridViewRow row = this.dataGridView1.Rows[e.RowIndex];
textBox2.Text = row.Cells["id"].Value.ToString();
textBox3.Text = row.Cells["lastname"].Value.ToString();
textBox4.Text = row.Cells["firstname"].Value.ToString();
}
}
问题是我不知道如何从中获取语法。你能帮助我,或者至少让我知道如何让第二种形式发挥作用吗?
答案 0 :(得分:0)
给你一个想法,
//event on which you want to show new form
{
if (e.RowIndex >= 0)
{
DataGridViewRow row = this.dataGridView1.Rows[e.RowIndex];
textBox2.Text = row.Cells["id"].Value.ToString();
textBox3.Text = row.Cells["lastname"].Value.ToString();
textBox4.Text = row.Cells["firstname"].Value.ToString();
Form Form2=new Form(row);
Form2.Show();
//can use Form2.ShowDialog(); according to requirements
}
}
//Constructor of form 2
public Form2(DataGridViewRow row)
{
InitializeComponent();
tbx1.Text = row.Cells[0].Value.ToString();
tbx2.Text = row.Cells[1].Value.ToString();
}