在gridView中查找单元格 [英] Find cell in a gridView

查看:94
本文介绍了在gridView中查找单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从列中获取单元格值,并遇到以下错误:

索引超出范围.必须为非负数,并且小于集合的大小.
参数名称:索引



这是我的代码,但不确定,我无法按名称调用该列,这不允许我这样做.

 受保护的 无效 btnSearchEmployees_Click(对象发​​件人,EventArgs e)
   {
       字符串 n = grdAvailableStuff.Rows [ 2 ].RowIndex.ToString();
       MessageBox.Show(n);
   } 

解决方案

当您获取网格中某个单元格的值时,您需要指定单元格位置

grid.Rows[0].Cells[0].Text.ToString();


检索第一行中第一个单元格的值

dataGridView.CurrentRow.Cells["//Column Name here"].Value


它将检索您的单元格值.


Am trying to get cell value from a columm and am geting the error below:

Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index



This is my code but am not sure about it and i cant call the column by name it does not allow me to do that.

protected void btnSearchEmployees_Click(object sender, EventArgs e)
   {
       string n = grdAvailableStuff.Rows[2].RowIndex.ToString();
       MessageBox.Show(n);
   }

解决方案

when your getting the value of a cell in grid , u require to specify cell position

grid.Rows[0].Cells[0].Text.ToString();


that retrieves the cell value of first one in first row


dataGridView.CurrentRow.Cells["//Column Name here"].Value


It retrieve your cell value.


这篇关于在gridView中查找单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆