如何找出其中的DataGridView行目前在屏幕上? [英] How to find out which DataGridView rows are currently onscreen?

查看:337
本文介绍了如何找出其中的DataGridView行目前在屏幕上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的C#(2010)应用程序,我在虚拟模式一个DataGridView持有几千行。是否有可能找出哪些细胞在此刻都在屏幕上?


解决方案

 公共无效GetVisibleCells(DataGridView中DGV)
{
VAR vivibleRowsCount = dgv.DisplayedRowCount(真);
VAR firstDisplayedRowIndex = dgv.FirstDisplayedCell.RowIndex;
VAR lastvibileRowIndex =(firstDisplayedRowIndex + vivibleRowsCount) - 1;
为(INT的rowIndex = firstDisplayedRowIndex; rowIndex位置< = lastvibileRowIndex; rowIndex位置++)
{
细胞无功= dgv.Rows [rowIndex位置] .Cells;
的foreach(在细胞中的DataGridViewCell细胞)
{
如果(cell.Displayed)
{
//这种细胞可见...
//您的代码放在这里...
}
}
}
}

更新:现在找到可见单元格


In my C# (2010) application I have a DataGridView in Virtual Mode which holds several thousand rows. Is it possible to find out which cells are onscreen at the moment?

解决方案

    public void GetVisibleCells(DataGridView dgv)
    {
        var vivibleRowsCount = dgv.DisplayedRowCount(true);
        var firstDisplayedRowIndex = dgv.FirstDisplayedCell.RowIndex;
        var lastvibileRowIndex = (firstDisplayedRowIndex + vivibleRowsCount) - 1;
        for (int rowIndex = firstDisplayedRowIndex; rowIndex <= lastvibileRowIndex; rowIndex++)
        {
            var cells = dgv.Rows[rowIndex].Cells;
            foreach (DataGridViewCell cell in cells)
            {
                if (cell.Displayed)
                {
                    // This cell is visible...
                    // Your code goes here...
                }
            }
        }
    }

Updated: It now finds visible cells.

这篇关于如何找出其中的DataGridView行目前在屏幕上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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