AmatVictorialCuram

C#——DataGridView选中行,在TextBox中显示选中行的内容,在DataGridView的SelectionChanged实践中设置如下代码

private void dataGridView1_SelectionChanged(object sender, EventArgs e)

{

int index = dataGridView1.SelectedRows[0].Index; //获取选中行的行号

textBox1.Text = dataGridView1.Rows[index].Cells[0].Value.ToString();

textBox2.Text = dataGridView1.Rows[index].Cells[1].Value.ToString();

 

this.textBox_ID.Text = this.dataGridView1.SelectedRows[0].Index.ToString();

this.textBox_CityName.Text=this.dataGridView1.CurrentRow.Cells[1].Value.ToString();//按照这种写法也可以

this.textBox_CityCode.Text = this.dataGridView1.CurrentRow.Cells[2].Value.ToString();

this.textBox_District.Text = this.dataGridView1.CurrentRow.Cells[3].Value.ToString();

this.textBox_Population.Text = this.dataGridView1.CurrentRow.Cells[4].Value.ToString();

}

分类:

技术点:

相关文章:

  • 2022-01-13
  • 2022-12-23
  • 2022-12-23
  • 2021-11-14
  • 2021-11-14
  • 2021-11-14
  • 2022-02-17
  • 2021-09-20
猜你喜欢
  • 2021-09-20
  • 2022-12-23
  • 2022-12-23
  • 2021-11-14
  • 2021-11-14
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案