在我的C#(2010)应用程序中,我有一个DataGridView在虚拟模式,它拥有数千行.目前可以找出哪些单元格在屏幕上?
解决方法
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... } } } }
更新:它现在找到可见的单元格.