Full Explanation - How to cancel row delete at rowdeleting

better_at_medianis.net
Date: 12/27/04

  • Next message: better_at_medianis.net: "Re: Cancel row delete in a datagrid."
    Date: 27 Dec 2004 14:02:55 -0800
    
    

    Full Explanation - How to cancel row delete at rowdeleting

    This problem solution satisfies in complete.
    Code is in C#, but if you need just translate to vb.net, and it will
    works too.

    Idea is to throw exception which abort (cancel) delete command at
    rowdeleting.
    We catch this exception at application level, and if we detect that is
    "our" exception, just do nothing.
    Silent pass thought.

    Once you add this method, you can use for all deleting, changing or all
    other stops, which you may need.

    Best Regards
    Milan Better

    1.Step is to declare our Exception (so we can detect at application
    level which exception is our)

    public class myDataException :Exception
    {

    }

    2.Step is to add event handler Application.ThreadException, in main
    function of our project

    [STAThread]
    static void Main()
    {
    Application.ThreadException +=new
    System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
    Application.Run(new MainForm());
    }

    private static void Application_ThreadException(object sender,
    System.Threading.ThreadExceptionEventArgs e)
    {
    //Fill here
    }

    3.Step is fill event handler we just created!

    private static void Application_ThreadException(object sender,
    System.Threading.ThreadExceptionEventArgs e)
    {
    if(e.Exception is myDataException)
    {
    return; //if this is our exception, just pass trought silent
    }
    else throw e.Exception; //all other exceptions which we do not handle
    }

    4.Step is fire exception at rowdeleting event handler

    private void myTableRowDeleting(object sender, myTableRowChangeEvent e)
    {
                    throw new myDataException();
            }


  • Next message: better_at_medianis.net: "Re: Cancel row delete in a datagrid."

    Relevant Pages

    • Re: Question - How to Cancel all Changes to a Dataset
      ... Full Explanation - How to cancel row delete at rowdeleting ... We catch this exception at application level, and if we detect that is ... private static void Application_ThreadException(object sender, ...
      (microsoft.public.dotnet.framework.adonet)
    • Re: Fastest way to split a file by columns?
      ... ByteBuffer buf = new ByteBuffer; ... // process exception. ... static void initializeStream() throws Exception { ... if (pos>= buf.length) { ...
      (comp.lang.java.programmer)
    • Re: Threading
      ... now I see why I was sceptic about the thread abort exception. ... tried a similar scenario in the default domain. ... static void ThreadProc() ...
      (microsoft.public.dotnet.languages.csharp)
    • Re: Check DateTime format
      ... "Jon Skeet " wrote: ... >> format. ... >> inefficient - catching the exception that is. ... static void Time ...
      (microsoft.public.dotnet.general)
    • Re: Check DateTime format
      ... > inefficient - catching the exception that is. ... You can use a regular expression to check the format, ... static void Time ... static readonly Regex Expression = new Regex ...
      (microsoft.public.dotnet.general)

    Loading