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. DataSource binding problem

DataSource binding problem

Scheduled Pinned Locked Moved C#
javascriptwpfwcfhelp
5 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.
  • J Offline
    J Offline
    Johnny 0
    wrote on last edited by
    #1

    Hi, I have a problem binding a DataSource object to multiple TextBoxes on the same form. It seems that the TextBox object is not dynamic, it doesn't change its Text value if the datasource changes. So I did a small experiment to prove this. In a form I initialize three controls and a Members object(derived from a DataSet): Note also that mem[0] returns a DataTable. Members mem = new Members(); mem.ReadRange(1004, 1004); binding = new BindingSource(mem[0], null); textBox1.DataBindings.Add("Text", binding, "FirstName"); textBox2.DataBindings.Add("Text", binding, "FirstName"); dataGridView1.DataSource = mem[0]; Here if I type data in the TextBox1, the datagrid reacts and shows me the modified data on Leave, but TextBox2 doesn't react. Same reaction for TextBox2. If I modify data in the DataGrid's column, none of the Textboxes react until BindingSource.Position changes. So I need a way to make the two text boxes to look at the state of the BindingSource adn detect any changes and react to it I tried also to detect events on BindingSource and BindingSource.CurrencyManager and nothig fires when leaving one of the TextBoxes. Really :confused:

    J 1 Reply Last reply
    0
    • J Johnny 0

      Hi, I have a problem binding a DataSource object to multiple TextBoxes on the same form. It seems that the TextBox object is not dynamic, it doesn't change its Text value if the datasource changes. So I did a small experiment to prove this. In a form I initialize three controls and a Members object(derived from a DataSet): Note also that mem[0] returns a DataTable. Members mem = new Members(); mem.ReadRange(1004, 1004); binding = new BindingSource(mem[0], null); textBox1.DataBindings.Add("Text", binding, "FirstName"); textBox2.DataBindings.Add("Text", binding, "FirstName"); dataGridView1.DataSource = mem[0]; Here if I type data in the TextBox1, the datagrid reacts and shows me the modified data on Leave, but TextBox2 doesn't react. Same reaction for TextBox2. If I modify data in the DataGrid's column, none of the Textboxes react until BindingSource.Position changes. So I need a way to make the two text boxes to look at the state of the BindingSource adn detect any changes and react to it I tried also to detect events on BindingSource and BindingSource.CurrencyManager and nothig fires when leaving one of the TextBoxes. Really :confused:

      J Offline
      J Offline
      Johnny 0
      wrote on last edited by
      #2

      Replying to myself but any better suggestions are welcomed I used the .Leave event on the TextBoxes to force a BindinSource.EdnEdit(); But now I have to manipulate every control individually. Is there a better wayto do this ? Thanks in advance for any input :-D

      U 1 Reply Last reply
      0
      • J Johnny 0

        Replying to myself but any better suggestions are welcomed I used the .Leave event on the TextBoxes to force a BindinSource.EdnEdit(); But now I have to manipulate every control individually. Is there a better wayto do this ? Thanks in advance for any input :-D

        U Offline
        U Offline
        Urs Enzler
        wrote on last edited by
        #3

        I didn't comprehend your sample completly but some basics about binding: - values in bound controls get updated when + BindingSource.ResetCurrentItem is called + a PropertyChanged event on the bound object is fired (see INotifyPropertyChanged) - Leave on TextBox does not lead to a BindingSource.EndEdit, but EndEdit will cause validation on the control without losing focus. And as a last thought: binding is a pain when you have to program UIs with controls that depend on each other - I's suggest using a variation of the MVP (mode view presenter) pattern (Presenter First or Passive View are my personal favourites ;-) ) Hope this helps a bit!

        -^-^-^-^-^- no risk no funk

        J 1 Reply Last reply
        0
        • U Urs Enzler

          I didn't comprehend your sample completly but some basics about binding: - values in bound controls get updated when + BindingSource.ResetCurrentItem is called + a PropertyChanged event on the bound object is fired (see INotifyPropertyChanged) - Leave on TextBox does not lead to a BindingSource.EndEdit, but EndEdit will cause validation on the control without losing focus. And as a last thought: binding is a pain when you have to program UIs with controls that depend on each other - I's suggest using a variation of the MVP (mode view presenter) pattern (Presenter First or Passive View are my personal favourites ;-) ) Hope this helps a bit!

          -^-^-^-^-^- no risk no funk

          J Offline
          J Offline
          Johnny 0
          wrote on last edited by
          #4

          Your Model View Presenter interested me, I have no intention on implementing this for my current project but I will definitely look into this for the future. I didn't find a lot of literature on the subject, it would be of everybody's interest if you had reading suggestion (specifically a good book) on the subject of MVP model. Thanks a lot for your input

          U 1 Reply Last reply
          0
          • J Johnny 0

            Your Model View Presenter interested me, I have no intention on implementing this for my current project but I will definitely look into this for the future. I didn't find a lot of literature on the subject, it would be of everybody's interest if you had reading suggestion (specifically a good book) on the subject of MVP model. Thanks a lot for your input

            U Offline
            U Offline
            Urs Enzler
            wrote on last edited by
            #5

            Unfortunately, there isn't too much in the internet about this topic. Either it's very abstract and difficult to transform in real world applications or it's a very simple description of MVP that lacks any information about all the surroundings. There are also quite a few different approaches (classic MVP, Presenter First, Passive View, ...). Therefore, I can't point you to a good article about MVP. Maybe I should write one on my own :-)

            -^-^-^-^-^- no risk no funk

            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