如何将网格滚动到selectedindex. [英] how to scroll grid to selectedindex.

查看:60
本文介绍了如何将网格滚动到selectedindex.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有一百行的网格(gridview中没有复选框),我正在通过
搜索网格中的记录 一个搜索按钮,搜索按钮位于网格外部.如果找到记录,则该行将突出显示.

我的问题是我想向下滚动页面到突出显示的行.

我怎样才能做到这一点??

预先感谢.

I have a grid with hundred rows (no check boxes in gridview), i am searching for the records in the grid through
a search button, search button is located out side the grid. if record is found, then the row will be highlighted.

My problem is i want to scroll down the page to the row highlighted.

how can i do that??

Thanks in advance.

推荐答案

GridViewRow row = grVw.SelectedRow;
row.Cells [0] .Focus();

通过添加这两行,我们可以滚动网格,但是Focus仅适用于可编辑控件.诸如复选框,超链接字段,链接按钮等示例.
GridViewRow row = grVw.SelectedRow;
row.Cells[0].Focus();

By adding these two lines we can scroll the grid.But Focus will work only for editable controls. example like checkbox,hyperlinkfield,linkbutton etc.


有几种滚动DataGridView的方法-首先设置CurrentCell属性会自动将单元格滚动到视图中.您还可以设置FirstDisplayScrollingRowIndex来手动滚动网格.
There are a few ways to scroll the DataGridView - First setting the CurrentCell property automatically scrolls the cell into view. You can also set the FirstDisplayScrollingRowIndex to scroll the grid manually.


尝试一下..

全局声明这两个变量..

try this..

declare these two variables globally..

int pageindex = -1;
int rowindex = -1;



做你的搜索..



do your search..

for (int i = 0; i < grid_view.PageCount; i++)
       {
           grid_view.PageIndex = i;
           grid_view.DataSource = ds;
           grid_view.DataBind();
           foreach (GridViewRow row in grid_view.Rows)
           {
               //your search match condition
               // if match
               pageindex = i;
               rowindex = row.RowIndex;
               break;
           }
           if (pageindex > 0)
           {
               break;
           }
       }

       grid_view.PageIndex = pageindex;
       grid_view.DataSource = ds;
       grid_view.DataBind();



稍后发生数据绑定事件..



later on databound event..

if(grid_view.PageIndex == pageindex)
 {
      if(e.Row.RowIndex == rowindex)
      {
          e.Row.BackColor = System.Drawing.Color.Red;
      }
 }



希望它能工作..



hope it works..


这篇关于如何将网格滚动到selectedindex.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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