winforms DevExpress winform:获取聚焦行的可见索引

iovurdzv  于 2023-06-24  发布在  其他
关注(0)|答案(2)|浏览(113)

我正在使用窗口窗体devExpress extragrid控件,我想获得所选行的可见行索引。在网格视图中,有数百行,我向下滚动,然后选择网格中的第一个可见行,它应该给予我0作为可见行索引。我尝试了FocusedRowChange事件中的方法,

gridView1.GetVisibleIndex(e.FocusedRowHandle)

它应该工作,但令人惊讶的是没有工作。谁能帮帮我?

e4eetjau

e4eetjau1#

GetVisibleIndex返回行的可见索引,而不考虑滚动位置。若要计算关于顶部可见行的行可见索引,请从返回值中减去TopRowIndex。

nwo49xxi

nwo49xxi2#

GridCell CurrentCell { get; set ; }
private void gridView1_MouseDown(object sender, MouseEventArgs e)
{
    if (e.Button == System.Windows.Forms.MouseButtons.Left)
    {
         CurrentCell = null;
        GridHitInfo hitInfo = gridView1.CalcHitInfo(e.Location);
        if (hitInfo.HitTest == GridHitTest.RowCell)
        {
            CurrentCell = new GridCell(hitInfo.RowHandle, hitInfo.Column);
        }
    }
}

结果:gridView1.FocusedRowHandle == CurrentCell.RowHandle;

相关问题