简体   繁体   中英

How to get selected row index in devexpress gridcontrol?

I have devexpress gridcontrol which looks like that: 在此处输入图片说明

I have click event on this red X button:

private void delete_button_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
{

}

How can get there row index where this button is ?

您可以使用GridView.FocusedRowHandle属性:

 view.DeleteRow(view.FocusedRowHandle);

You cannot access rows on GridControl , since this is just a container for the views. As I can see from your picture you're using GridView . When you press the delete button, focused row changes and you can access it via FocusedRowHandle .

private void delete_button_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
{
  var gv = myGridControl.MainView as GridView;
  var index = gv.FocusedRowHandle;

  gv.DeleteRow(index);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM