首页 技术 正文
技术 2022年11月17日
0 收藏 700 点赞 4,655 浏览 1306 个字

1、 DataGridView 控件详细解说:http://blog.csdn.net/qq_24304137/article/details/51068768


2、

DataGridView的几个基本操作:
1、获得某个(指定的)单元格的值:
dataGridView1.Row[i].Cells[j].Value;
2、获得选中的总行数:
dataGridView1.SelectedRows.Count;
3、获得当前选中行的索引:
dataGridView1.CurrentRow.Index;
4、获得当前选中单元格的值:
dataGridView1.CurrentCell.Value;
5、取选中行的数据
string[] str = new string[dataGridView.Rows.Count];
for(int i;i<dataGridView1.Rows.Count;i++)
{
if(dataGridView1.Rows[i].Selected == true)
{
str[i] = dataGridView1.Rows[i].Cells[1].Value.ToString();
}
}
7、获取选中行的某个数据
int a = dataGridView1.SelectedRows.Index;

dataGridView1.Rows[a].Cells[“你想要的某一列的索引,想要几就写几”].Value;

获得某个(指定的)单元格的值: dataGridView1.Row[i].Cells[j].Value; Row[i] 应该是Rows[i]

int a=dataGridView1.CurrentRow.Index;
string str=dataGridView1.Row[a].Cells[“strName”].Value.Tostring();

selectedRows[0]当前选中的行
.cell[列索引].values 就是当前选中行的某个单元格的值

DataGridView1.SelectedCells(0).Value.ToString 取当前选择单元内容
DataGridView1.Rows(e.RowIndex).Cells(2).Value.ToString 当前选择单元第N列内容


3、datagridview获取某个单元格的值

首先是列定位
dataGridView1.Rows[i].Cells[*].value.tostring();
*这里的参数可以是int index,也可以是string columnName.
column除了name,index以外还有个text,也就是列头文本.name和index可以直接定位,text不行.
想要用text定位就得建一个方法,循环dataGridView.columns,通过匹配text得到name或者index属性.(用这个方法还得保证列标题文本在表格内唯一,否则不一定能定位到想要的列)

4、datagridview中最后一行某列的数据DataGridView1.Rows[DataGridView1.RowCount-1].Cells[列号].Value

【欢迎转载】

转载请表明出处: 乐学习

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,497
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,910
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,744
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,498
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,135
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,299