WPF DataGrid - get row number which mouse cursor is on

前端 未结 4 1934
情歌与酒
情歌与酒 2021-01-18 23:24

I am looking to get the row number of which the mouse cursor is on in a DataGrid (So basically on a MouseEnter event) so I can get the DataGridRow item of which the ItemSour

4条回答
  •  鱼传尺愫
    2021-01-18 23:44

    This worked for me.

    
        
            
        
    
    
    private void Row_MouseEnter(object sender, MouseEventArgs e)
    {
        int index = dataGridView.ItemContainerGenerator.IndexFromContainer((DataGridRow)sender);
    }
    

提交回复
热议问题