In WinForms, how can I create a delete button in DevExpress GridControl?

I am trying to create a delete button to the right of each row in the DevExpress GridControl, for example:

enter image description here

What I did was add another column and set its ColumnEdit property to the RepositoryItemButtonEdit instance. I am handling a ButtonClick event to remove a row.

I can determine which line I am joining from this code:

myGridView.GetRow(myGridView.FocusedRowHandle); 

Since I do not need a text editor on my button, I set the TextEditStyle to HideTextEditor.

By default, the button shows an ellipsis.

To remove the ellipsis, I adjusted the Buttons property to RepositoryItemButtonEdit. I set the view in Glyph and set the image to the X icon.

Unfortunately, this simply removes the button.

Does anyone know a better way to do this or a way to show a button with an image on it in each grid line?

+4
source share
2 answers

I found that there is actually a delete button. So, I do everything as in the question, but instead of choosing the Glyph view, I select Delete, and I do not need to select the image.

+3
source

I summed up what I found in the DevExpress forum :

Use the ButtonEdit control and set the TextEditStyle property to HideTextEditor . The repository element has a Buttons collection through which you can add a signature, image, etc.

In the Buttons collection, change the View property to Symbol. You can use the CustomRowCellEdit event to conditionally apply the editors individually. Make sure the Button Kind property is set to "Glyph" and set the Caption property to whatever text you want:

 DevExpress.XtraEditors.Repository.RepositoryItemButtonEdit buttonEdit = new DevExpress.XtraEditors.Repository.RepositoryItemButtonEdit(); buttonEdit.Buttons[0].Kind = DevExpress.XtraEditors.Controls.ButtonPredefines.Glyph; buttonEdit.Buttons[0].Caption = "X"; buttonEdit.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.HideTextEditor; e.RepositoryItem = buttonEdit; 

You should handle the GridView CustomRowCellEdit event, build a new RepositoryItemButtonEdit and assign it an e.RepositoryItem property .

Let me know if this works.

+3
source

All Articles