User Control Databindings don't work

G

Guest

I have a user control and I have several textboxes on it. I build the user
control and dropped it on a window's application. I have a typed dataset in
the window's application. I'm trying to bind the controls within the user
control to this dataset. I have the following code in the user control. This
lets me bind controls in the user control to the dataset in the window'
application.


<DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
Public Property TextBox1_Binding() As
System.Windows.Forms.ControlBindingsCollection
Get
Return TextBox1.DataBindings
End Get
Set(ByVal Value As System.Windows.Forms.ControlBindingsCollection)
Dim bindings As System.Windows.Forms.ControlBindingsCollection
Dim b As Binding
bindings = CType(Value,
System.Windows.Forms.ControlBindingsCollection)
TextBox1.DataBindings.Clear()
For Each b In bindings
TextBox1.DataBindings.Add(b)
Next b
End Set
End Property

Now the problem is if I change the bindingcontext postion to step through
records, the values in the user control's controls are not refreshing. They
just show the first record values. What do I need to do to be able to refresh
these values?
 
J

Jeffrey Tan[MSFT]

Hi mach2,

Thanks for your post.

I am not sure how you get the currencymanager of current databinding and
change the position, normally, we can use
Binding.BindingManagerBase.Position property to refer it and manipulate it.

I have writen a sample project, which uses your pasted TextBox1_Binding
property to expose the internal textbox DataBindings to UserControl level.
I can successfully change the textbox display with the code snippet below:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.SqlDataAdapter1.Fill(Me.DataSet11)
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Me.UserControl11.TextBox1_Binding(0).BindingManagerBase.Position =
Me.UserControl11.TextBox1_Binding(0).BindingManagerBase.Position + 1
End Sub

Hope it helps.
===================================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
J

Jeffrey Tan[MSFT]

Hi mach2,

Does my reply make sense to you? Is your problem resolved? Please feel free
to tell me, thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
G

Guest

Jeffrey,
I actually did the samething to resolve the issue. In the user control I've
set up a method that does exactly what you've suggested and from the window's
app I called that method. The funny thing is if you set one of the control's
binding position, all the other controls' binding positions changed
accordingly.

Thank you
 
J

Jeffrey Tan[MSFT]

Hi mach2,

I am glad your problem is resolved.

For your further concern, yes, this is the default behavior of .Net Winform
databinding. In winform databinding, once several controls will bind the
same datasource, with the same datamember, then winform will keep the
synchronization with these controls. This is a wonderful feature of winform
databinding.

Hope this helps

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top