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. I know how to clear textboxs on my form at one time but what if they are bound?

I know how to clear textboxs on my form at one time but what if they are bound?

Scheduled Pinned Locked Moved C#
helptutorialquestionannouncement
3 Posts 2 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.
  • T Offline
    T Offline
    tonyonlinux
    wrote on last edited by
    #1

    I understand I can do the following to remove text from controls in this case the textbox

    private void add_Button_Click(object sender, EventArgs e)
    {
    foreach (Control control in recordinput_groupbox.Controls)
    {
    if(control.GetType() == typeof(TextBox))
    {
    //control.DataBindings.Clear();
    control.Text = string.Empty;

                           }
                    }
    

    but what if they are bound? Notice the control.Databindings.clear(); that works but the problem is after I get done updating records or adding/ I want to reload the data so the user can select another item if they wish via the bindingnavigator to update. when the databinding is cleared then obviously it is no longer bound. Is it wise to simply make a function to bind the controls back after the update or is there a easier better way of handling this? I tried to search on here and good for it but It never really addressed the per say correct way. thanks for your time.

    A 1 Reply Last reply
    0
    • T tonyonlinux

      I understand I can do the following to remove text from controls in this case the textbox

      private void add_Button_Click(object sender, EventArgs e)
      {
      foreach (Control control in recordinput_groupbox.Controls)
      {
      if(control.GetType() == typeof(TextBox))
      {
      //control.DataBindings.Clear();
      control.Text = string.Empty;

                             }
                      }
      

      but what if they are bound? Notice the control.Databindings.clear(); that works but the problem is after I get done updating records or adding/ I want to reload the data so the user can select another item if they wish via the bindingnavigator to update. when the databinding is cleared then obviously it is no longer bound. Is it wise to simply make a function to bind the controls back after the update or is there a easier better way of handling this? I tried to search on here and good for it but It never really addressed the per say correct way. thanks for your time.

      A Offline
      A Offline
      AspDotNetDev
      wrote on last edited by
      #2

      I assume you are using WPF (I could be wrong)... I'm not quite sure what you are trying to accomplish. It sounds like you want to clear a TextBox (for example) then add the binding back to it later. Perhaps you could just change the value the TextBox.Text property is bound to (i.e., set it to an empty string)?

      [Forum Guidelines]

      T 1 Reply Last reply
      0
      • A AspDotNetDev

        I assume you are using WPF (I could be wrong)... I'm not quite sure what you are trying to accomplish. It sounds like you want to clear a TextBox (for example) then add the binding back to it later. Perhaps you could just change the value the TextBox.Text property is bound to (i.e., set it to an empty string)?

        [Forum Guidelines]

        T Offline
        T Offline
        tonyonlinux
        wrote on last edited by
        #3

        Yes it is a winform. Well, what the issue is is i can do empty.string and all is fine. However, when the user goes to input data and hits tab to go to the next field it automatically populates with the old bound data. I don't have autocomplete enabled unless it's somehow by default. lets say the original data for AuthorLast_Textbox is Smith i hit add and it wipes it to the empty string that is fine. but when if i'm on Authorfirst_textbox and type in Sam and then hit tab I will automatically get smith populated in the authorlast_textbox. I assume that is because it is databound. thanks for your help by the way.

        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