1、如果有超过一屏的数据,想通过关键字查找到相关记录,然后再定位之,做法如下:
遍历所有行,把某单元格的值和关键字对比,找到后清除所有选择行,然后把当前行设为选择,然后把grid的CurrentCell设置为当前行的某个可见单元格即可,效果就会自动跳到定位好的行上。
示例代码:
string InputStr=txtFindSp.Text;
foreach(DataGridViewRow dvr in dgvSp.Rows)
{
    
if(dvr.Cells[2].Value.ToString().StartsWith(InputStr))
    
{
        dgvSp.ClearSelection();
        dvr.Selected
=true;
        dgvSp.CurrentCell=dvr.Cells[
1];
        
break;
    }

}

2、数据绑定
其实很简单,只要实例化一个BindingSource对象,然后把BindingSource对象的DataSource属性设置为DataTable或者DataSet,然后再将DataGridView的DataSource设置为BindingSource对象即可。
posted on 2006-09-04 20:15  spgoal  阅读(18342)  评论(4编辑  收藏  举报