Lali
Lali

Reputation: 2866

DevExpress winform: Get Visible Index of focused row

I am using window forms devExpress extragrid control and I want to get visible row index of the selected row. In the gridview, there are hundreds of the rows, I scroll down and then select first visible row in the grid, it should give me 0 as visible row index. I tried the ways in FocusedRowChange event,

gridView1.GetVisibleIndex(e.FocusedRowHandle)

It should work but surprisingly not working. Can any one help me?

Upvotes: 1

Views: 2909

Answers (2)

Phu Thien
Phu Thien

Reputation: 1

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);
        }
    }
}

Result: gridView1.FocusedRowHandle == CurrentCell.RowHandle;

Upvotes: -1

Dmitrii Babich
Dmitrii Babich

Reputation: 499

The GetVisibleIndex returns a visible index of a row regardless a scroll position. To calculate a row visible index regarding the top visible row, subtract TopRowIndex from the returned value.

Upvotes: 1

Related Questions