Search code examples
buttonrepositorydevexpressxtragrid

How can i get xtragrid row index via repository button in gridcell?


I have buttons in xtragrid cell . i want to get row index when i clicked to repository button item. How can i get cell info or index..

I wanna show cell info at anotherp page which respository button clicked in row cell..

Can you help me ? Thanks for advice..


Solution

  • To get the information about Grid HitInfo check the Hit Information Overview and Samples of Using Hit Information documentation:

    private void gridView1_MouseDown(object sender, MouseEventArgs e) {
        // obtaining hit info 
        GridHitInfo hitInfo = gridView1.CalcHitInfo(new Point(e.X, e.Y));
        if (((e.Button & MouseButtons.Right) != 0) && (hitInfo.InRow)  && 
            (!gridView1.IsGroupRow(hitInfo.RowHandle))) {
            // switching focus 
            gridView1.FocusedRowHandle = hitInfo.RowHandle;
            // showing the custom context menu 
    
            ViewMenu menu = new ViewMenu(gridView1);
            DXMenuItem menuItem = new DXMenuItem("DeleteRow", 
              new EventHandler(DeleteFocusedRow));
            menuItem.Tag = gridView1;
            menu.Items.Add(menuItem);
            menu.Show(hitInfo.HitPoint);
        }        
    }
    

    Check this:

    private void repositoryItemButtonEdit_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
    {
        myGridView.DeleteRow(myGridView.FocusedRowHandle);  /// you can get focusedRowHandle here
    }
    

    Reference:
    Winforms XtraGrid Delete Row Button
    Delete button on each row of grid - how do we prevent the user from typing text in the new column with the delete button

    Edit: Refere this Devexpres thread: Cannot get the rowhandle to delete a row using RepositoryItemButtonEdit