Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. how to avoid a leave event after it is called

how to avoid a leave event after it is called

Scheduled Pinned Locked Moved C#
questionhelptutorial
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    eyalle
    wrote on last edited by
    #1

    hello, im looking for a solution with a slight problem that im sure it is possible, but i cant find anything about it on the web. In my code, im calling a leave event out of a control that check's if the control has made any changes (txtBox, combo Box...) raising a question telling the user that changes weren't saved. if the user click's on Cancel button, i want him to stay in the control and not actually leave like he initially did. How can i do it ? Thanks

    private void TabControlChars_Leave(object sender, EventArgs e)
    {
    DataTable charChanges = null;

            if (charsTypeDT != null)
            {
                charChanges = charsTypeDT.GetChanges();
            }
            else if (charsDT != null)
            {
                charChanges = charsDT.GetChanges();
            }
    
            if (charChanges != null)
            {
                DialogResult result;
                result = MessageBox.Show("Changes were made without saving !!\\n"
                               + "All Changes will be lost ...", "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                if (result == DialogResult.Cancel)
                {
                    ???
                }
            }
        }
    
    D L 2 Replies Last reply
    0
    • E eyalle

      hello, im looking for a solution with a slight problem that im sure it is possible, but i cant find anything about it on the web. In my code, im calling a leave event out of a control that check's if the control has made any changes (txtBox, combo Box...) raising a question telling the user that changes weren't saved. if the user click's on Cancel button, i want him to stay in the control and not actually leave like he initially did. How can i do it ? Thanks

      private void TabControlChars_Leave(object sender, EventArgs e)
      {
      DataTable charChanges = null;

              if (charsTypeDT != null)
              {
                  charChanges = charsTypeDT.GetChanges();
              }
              else if (charsDT != null)
              {
                  charChanges = charsDT.GetChanges();
              }
      
              if (charChanges != null)
              {
                  DialogResult result;
                  result = MessageBox.Show("Changes were made without saving !!\\n"
                                 + "All Changes will be lost ...", "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                  if (result == DialogResult.Cancel)
                  {
                      ???
                  }
              }
          }
      
      D Offline
      D Offline
      dan sh
      wrote on last edited by
      #2

      Try setting focus back to the textbox. You can also place the code in the Validating event and then use Cancel property of the CancelEventArgs there to remain in the textbox.

      50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!

      1 Reply Last reply
      0
      • E eyalle

        hello, im looking for a solution with a slight problem that im sure it is possible, but i cant find anything about it on the web. In my code, im calling a leave event out of a control that check's if the control has made any changes (txtBox, combo Box...) raising a question telling the user that changes weren't saved. if the user click's on Cancel button, i want him to stay in the control and not actually leave like he initially did. How can i do it ? Thanks

        private void TabControlChars_Leave(object sender, EventArgs e)
        {
        DataTable charChanges = null;

                if (charsTypeDT != null)
                {
                    charChanges = charsTypeDT.GetChanges();
                }
                else if (charsDT != null)
                {
                    charChanges = charsDT.GetChanges();
                }
        
                if (charChanges != null)
                {
                    DialogResult result;
                    result = MessageBox.Show("Changes were made without saving !!\\n"
                                   + "All Changes will be lost ...", "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                    if (result == DialogResult.Cancel)
                    {
                        ???
                    }
                }
            }
        
        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Your logic should ideally be placed in Cancel button's Click event.

        E 1 Reply Last reply
        0
        • L Lost User

          Your logic should ideally be placed in Cancel button's Click event.

          E Offline
          E Offline
          eyalle
          wrote on last edited by
          #4

          Sorry, but i didnt get you.. the message Box is created inside the Leave event so how can i put the event in the cancel button click event ?

          L 1 Reply Last reply
          0
          • E eyalle

            Sorry, but i didnt get you.. the message Box is created inside the Leave event so how can i put the event in the cancel button click event ?

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            I'm sorry, I got your question wrong. In your case, instead of using the Leave event, use the Validating event and if the user chooses cancel, set e.Cancel = true (e is the ValidatingEventArgs passed to the method).

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups