如何通过网格单元格中的存储库按钮获取XtraGrid行索引?

3

我在xtragrid单元格中有按钮。当我单击存储库按钮项时,我想获取行索引。如何获取单元格信息或索引?

我想在另一页上显示单击行单元格中的存储库按钮的单元格信息。

你能帮帮我吗? 感谢建议。

1个回答

3

要获取有关网格HitInfo的信息,请查看Hit Information Overview使用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主题:无法使用RepositoryItemButtonEdit获取行句柄来删除行


这里是代码:this.repositoryItemButtonEdit.Click += new System.EventHandler(this.repositoryItemButtonEdit_Click); 它出错了... 我该如何编写按钮事件呢?我使用了下面的代码: this.repositoryItemButtonEdit.Click += new DevExpress.XtraEditors.Controls.ButtonPressedEventHandler(this.repositoryItemButtonEdit_Click);但是报错:无法隐式转换类型“DevExpress.XtraEditors.Controls.ButtonPressedEventHandler”为“System.EventHandler”。谢谢回答。 - user825875
请检查以下代码:RepositoryItemButtonEdit rbtnEdit; private void SetLoopEdit() { rbtnEdit.Click += new EventHandler(rbtnEdit_Click); rbtnEdit.ButtonClick += new DevExpress.XtraEditors.Controls.ButtonPressedEventHandler(rbtnEdit_ButtonClick); }确保没有任何错误。 - Niranjan Singh

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接