c# winform DataGridView选择一整行的相关属性
2016-11-19 15:42
218 查看
1. 设置DataGridView的属性SelectionMode为FullRowSelect
这样就使DataGridView不是选择一个字段,而是选择一整行了
2. 设置DataGridView的属性MultiSelect为false
这样就使DataGridView不能够选择多行,只能选择一行了
3. 想得到某列的值是要判断DataGridView是否有选中的行
if (dataGridView1.SelectedCells.Count != 0)
{
//得到选中行的索引
int intRow = dataGridView1.SelectedCells[0].RowIndex;
//得到列的索引
int intColumn = dataGridView1.SelectedCells[0].ColumnIndex;
//得到选中行某列的值
string str = dataGridView1.CurrentRow.Cells[2].Value.ToString();
MessageBox.Show(str);
}
这样就使DataGridView不是选择一个字段,而是选择一整行了
2. 设置DataGridView的属性MultiSelect为false
这样就使DataGridView不能够选择多行,只能选择一行了
3. 想得到某列的值是要判断DataGridView是否有选中的行
if (dataGridView1.SelectedCells.Count != 0)
{
//得到选中行的索引
int intRow = dataGridView1.SelectedCells[0].RowIndex;
//得到列的索引
int intColumn = dataGridView1.SelectedCells[0].ColumnIndex;
//得到选中行某列的值
string str = dataGridView1.CurrentRow.Cells[2].Value.ToString();
MessageBox.Show(str);
}
相关文章推荐
- c# winform DataGridView选择一整行的相关属性
- C#列表所有IIS站点以及相关站点属性
- [C#][SAMPLE][CODE][Control]RichTextBox以及相关常见属性
- C#IO 文件读取笔记一(File类和Directory类相关属性,FileInfo类和DirectoryInfo类)
- 1、怎样设置C#OpenFileDialog(文件选择窗体)的指定路径、文件格式等属性(设置打开默认路径、文件格式、窗体显示文本)
- c#读取IIS中的站点相关属性代码
- Krpano学习:在C#中修改全景场景属性(C#操作全景vtour.xml文件及相关瓦片数据/panos/*.tiles)
- ListView中的分割线和定位选择item相关属性
- 利用getJson+ashx实现商品属性选择(C#)
- C#列表所有IIS站点以及相关站点属性
- c# 设置属性的样式(选择文件)
- 【C#属性理解】--与SQL交互用到的 【DataSet】相关
- C# VBA 填充Word表格 ,并随意转移单元格焦点或插入文本,及相关文字的颜色、粗体等相关属性。
- C#集合篇,在业务背景下(***产品升级管理):依赖注入,变量声明,三元表达式,常用字符串相关操作方法,ADO.NET,EF机制,T4模板自动生成实体类,ref变量巧用,属性实际运用,唯一性验证
- C#:LinkButton 控件 绑定数据时候 相关属性的注解
- C#列表所有IIS站点以及相关站点属性
- 与IDE相关的Attribute属性(C#)
- C#中,编写可选择任意属性转化成JSON
- C#中的自定义控件中的属性、事件及一些相关特性的总结(转)