C#——DataGridView选中行,在TextBox中显示选中行的内容
2015-12-22 12:27
357 查看
C#——DataGridView选中行,在TextBox中显示选中行的内容,在DataGridView的SelectionChanged实践中设置如下代码
privatevoiddataGridView1_SelectionChanged(objectsender, EventArgse)
{
intindex=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();
}
privatevoiddataGridView1_SelectionChanged(objectsender, EventArgse)
{
intindex=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();
}
相关文章推荐
- C# 值传递与引用传递的区别
- C#一键显示及杀死占用端口号进程
- (C#)Winform修改DateTimePicker控件的背景色Winform中日期控件DateTimePicker默认是不能修改背景色和边框色的
- c# 报表练习笔记(二)——父子报表 + 分组 + 图片
- c# 报表练习笔记(一)
- C# \\r\\n替换为\r\n
- [C#] 阅读Hashset的一些感想
- C#委托的介绍(delegate、Action、Func、predicate)
- C#根据当前时间获取周,月,季度,年度等时间段的起止时间
- c#语法笔记
- C# - 冒泡排序算法练手
- C#字符串的常用操作
- C#字符串的常用操作
- C#修饰符、字段、属性
- C# DataGridview转换为DataTable
- C# 读取EXCEL文件的三种经典方法
- C# 封装-属性
- C# 封装-属性
- C#中的泛型
- 一个C#序列化时循环引用的问题