如何找出屏幕上当前的DataGridView行?
在我的C#(2010)应用程序中,我在虚拟模式下有一个DataGridView,它拥有数千行。 是否有可能找出目前屏幕上的哪些细胞?
public void GetVisibleCells(DataGridView dgv) { var visibleRowsCount = dgv.DisplayedRowCount(true); var firstDisplayedRowIndex = dgv.FirstDisplayedCell.RowIndex; var lastvisibleRowIndex = (firstDisplayedRowIndex + visibleRowsCount) - 1; for (int rowIndex = firstDisplayedRowIndex; rowIndex <= lastvisibleRowIndex; rowIndex++) { var cells = dgv.Rows[rowIndex].Cells; foreach (DataGridViewCell cell in cells) { if (cell.Displayed) { // This cell is visible... // Your code goes here... } } } }
更新 :它现在找到可见的单元格。
我自己没有尝试过这个,但在我看来,使用DataGridView.GetRowDisplayRectangle确定一行的矩形并检查它是否与当前的DataGridView.DisplayRectangle重叠将是最佳选择。 Rectangle.IntersectsWith可用于执行此操作。
作为优化,我会在找到第一个可见行后使用DataGridView .DisplayedRowCount来确定哪些行可见。
上述就是C#学习教程:如何找出屏幕上当前的DataGridView行?分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注---计算机技术网(www.ctvol.com)!
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/cdevelopment/1025244.html