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. Windows Forms
  4. Toolstripbutton not validating textbox.

Toolstripbutton not validating textbox.

Scheduled Pinned Locked Moved Windows Forms
helpquestion
5 Posts 4 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.
  • P Offline
    P Offline
    priyamtheone
    wrote on last edited by
    #1

    I have a textbox, a standard button and a toolstrip containing a couple of buttons. In the validating event of the textbox i coded to check whether it is blank. If yes then it shows a message 'Enter Value'. When the standard button is clicked while the textbox is empty, it's validating properly and showing the message but when the toolstripbutton is clicked it's not not validating the textbox and no message is being shown. It seems that I gotto write the validation code explicitly in the toolstripbutton_click event which is too troublesome when there are multiple textboxes and toolstripbuttons on a single form. What I want to know is whether the textbox_validating can be fired while the toolstripbutton is clicked? Handling toolstrips is really a headache. Please help. I'm badly in need of it. Regards.

    R R 2 Replies Last reply
    0
    • P priyamtheone

      I have a textbox, a standard button and a toolstrip containing a couple of buttons. In the validating event of the textbox i coded to check whether it is blank. If yes then it shows a message 'Enter Value'. When the standard button is clicked while the textbox is empty, it's validating properly and showing the message but when the toolstripbutton is clicked it's not not validating the textbox and no message is being shown. It seems that I gotto write the validation code explicitly in the toolstripbutton_click event which is too troublesome when there are multiple textboxes and toolstripbuttons on a single form. What I want to know is whether the textbox_validating can be fired while the toolstripbutton is clicked? Handling toolstrips is really a headache. Please help. I'm badly in need of it. Regards.

      R Offline
      R Offline
      RobCroll
      wrote on last edited by
      #2

      This is an undocumented feature and appears to be by design. (don't you just hate that terminology) I guess it makes sense in a non-OOP way. When an event in the ToolStrip is raised, the control within the form that has focus, does not lose that focus! Therefore the validated/validating events of the control that has focus, are not raised. The approach I take is to refactor each validation and provide a method that calls all validations within a single method. It's nice to provide control by control validation but there is no guarantee that a control will ever gain or lose focus. You need an overall validation method to handle this. If your dealing with an underlying data source you may also want to look at the IDataErrorInfo interface.

      1 Reply Last reply
      0
      • P priyamtheone

        I have a textbox, a standard button and a toolstrip containing a couple of buttons. In the validating event of the textbox i coded to check whether it is blank. If yes then it shows a message 'Enter Value'. When the standard button is clicked while the textbox is empty, it's validating properly and showing the message but when the toolstripbutton is clicked it's not not validating the textbox and no message is being shown. It seems that I gotto write the validation code explicitly in the toolstripbutton_click event which is too troublesome when there are multiple textboxes and toolstripbuttons on a single form. What I want to know is whether the textbox_validating can be fired while the toolstripbutton is clicked? Handling toolstrips is really a headache. Please help. I'm badly in need of it. Regards.

        R Offline
        R Offline
        RaviRanjanKr
        wrote on last edited by
        #3

        priyamtheone wrote:

        Please help. I'm badly in need of it

        Oh! your question will be more clear when you mention your code so please mention it. whatever, you can create a function and call it as many time you want to perform it. you don't need to create command every time for same work.

        P 1 Reply Last reply
        0
        • R RaviRanjanKr

          priyamtheone wrote:

          Please help. I'm badly in need of it

          Oh! your question will be more clear when you mention your code so please mention it. whatever, you can create a function and call it as many time you want to perform it. you don't need to create command every time for same work.

          P Offline
          P Offline
          priyamtheone
          wrote on last edited by
          #4

          Well, calling common functionalities using methods is well known to everyone. That's not my question. What I asked for is whether textbox or other standard controls can be validated while toolstripbutton is clicked? As I learned gradually that toolstrip is not a control but a component and toolstripitems don't have CausesValidation property to cause them to validate any standard control on a form.

          P 1 Reply Last reply
          0
          • P priyamtheone

            Well, calling common functionalities using methods is well known to everyone. That's not my question. What I asked for is whether textbox or other standard controls can be validated while toolstripbutton is clicked? As I learned gradually that toolstrip is not a control but a component and toolstripitems don't have CausesValidation property to cause them to validate any standard control on a form.

            P Offline
            P Offline
            phil o
            wrote on last edited by
            #5

            So, if you want to validate your TextBox, you have to call the method from within your ToolStripItem_Click event handler. i.e. :

            private myToolStripItem_Click(object sender, ClickEventArgs e)
            {
            myTextBox_LostFocus(myTextBox, EventArgs.Empty);
            ...
            }

            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