c# – Trigger before ListView change – Education Career Blog

I want to have a trigger when the select item in a WPF ListView is about the change. So a “Changing” trigger. This is not available by default.
Is there a way to do this?

I need this because my ListView is bound to a list of Client. When the client selection changes, I want to ask the user if he wants to store his changes, but when I do this on the Changed event my UI already changes to the new client (due to bindings).

,

Take a look at the Validating event.

private void ListView1_Validating(object sender, System.ComponentModel.CancelEventArgs e)
{
   // Show messagebox and get response
   if(UserDoesntWantToSave)       
   {
      // Cancel the event
      e.Cancel = true;
   }
}

http://msdn.microsoft.com/en-us/library/system.windows.forms.control.validating.aspx

Leave a Comment