3

我在 xtragrid 单元格中有按钮。当我单击存储库按钮项时,我想获取行索引。我怎样才能获得细胞信息或索引..

我想在另一个页面上显示单元格信息,在行单元格中单击了存储库按钮..

你能帮助我吗 ?谢谢你的建议..

4

1 回答 1

3

要获取有关 Grid HitInfo 的信息,请查看Hit Information OverviewSamples of Using Hit Information文档:

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

检查这个:

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

参考:
Winforms XtraGrid 删除行按钮
网格每一行上的删除按钮 - 我们如何防止用户使用删除按钮在新列中键入文本

编辑: 参考这个 Devexpres 线程: Cannot get the rowhandle to delete a row using RepositoryItemButtonEdit

于 2013-01-29T10:26:00.140 回答