Hello,
is it possible to interact when the user clicks on the "remove" button on the list item in the property grid, in order I can show a confirm "Delete" dialog?
See attached image.
Hello Markus,
You can achieve the requested functionality by attaching an event handler to the xamPropertyGrid's "CommandExecuting" event and handle it the following way:- check if the command is "RemoveListEntry"- perform some additional checking (if necessary)- show the removal confirm dialog- cancel the event if the user does not confirm removal (which will cancel the CommandExecuted event and ultimately cancel the list item removal)
Here is an example on how you may implement it:
private void XamPropertyGrid1_CommandExecuting(object sender, PropertyGridCommandExecutingEventArgs e){ if (e.Command == PropertyGridCommandType.RemoveListEntry) { var result = MessageBox.Show("Are you sure you want to delete?", "Confirm", MessageBoxButton.YesNo); if (result != MessageBoxResult.Yes) { e.Cancel = true; } }}
Let me know if I may be of any further assistance.
Sincerely,Radko KolevSenior Software Developer
Hi all,
In this case, how can we get the value that will be removed from the list?
Hello Mladen,
In order to get the value that is removed from the list, I would recommend using the CommandParameter property of the event arguments of the CommandExecuting event referenced above. When the Command is the PropertyGridCommandType.RemoveListEntry, the e.CommandParameter (where 'e' is the event arguments) will return a PropertyGridPropertyItem, whose Value property will be the value that is removed from the list. For example, you can use the following code to do this:
if (e.Command == PropertyGridCommandType.RemoveListEntry) { PropertyGridPropertyItem item = e.CommandParameter as PropertyGridPropertyItem; var removedObj = item.Value; }
Please let me know if you have any other questions or concerns on this matter.