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