Hello. I have a basic situation when I need to update my bindings. How can I do it? I have a Form with 2 buttons and a TrackBar, that I modify the Maximum (5 or 10). When the value of TrackBar is 10 and I set the Maximum to 5, the value 10 are reduced to 5, but the binding (to textbox) does not reflect it. How can I update the textBox after the maximum value changes?
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Label1.DataBindings.Add("Text", Me.TrackBar1, "Value")
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Me.TrackBar1.Maximum = 5
End Sub
Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
Me.TrackBar1.Maximum = 10
End Sub
End Class

Best regards,
Sergiu |
| Sergiu Dudnic Thursday, August 13, 2009 8:58 AM |
All you need to do is just call the property setter, it will take care of notifying everyone of the change: Public Shadows Property Minimum() As Integer Get Return MyBase.Minimum End Get Set(ByVal value As Integer) If Me.Value < value Then Me.Value = value End If MyBase.Minimum = value End Set End Property (Do the same thing for Maximum and for SetRange if you plan to use it.) - Marked As Answer bySergiu Dudnic Tuesday, August 18, 2009 10:27 AM
-
|
| Michal Burger Friday, August 14, 2009 11:09 AM |
https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=483012
Best regards, Sergiu
As usual, Microsoft does not consider this issue "critical", and will not fix it.
Best regards, Sergiu - Marked As Answer bySergiu Dudnic Tuesday, August 18, 2009 10:26 AM
-
|
| Sergiu Dudnic Monday, August 17, 2009 9:05 AM |
Interesting. This one looks like a bug to me. If you create a handled for the ValueChanged event, it is not hit when changing the maximum value. So it looks like changing the Maximum value modifies the .Value property bug does not generate the ValueChanged event. www.insteptech.com ;
msmvps.com/blogs/deborahk
We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS! |
| DeborahK Thursday, August 13, 2009 7:15 PM |
This is a hack, but seemed to work for me:
Me.TrackBar1.Maximum = 5
Dim newValue As Integer = Me.TrackBar1.Value
Me.TrackBar1.Value = Me.TrackBar1.Minimum
Me.TrackBar1.Value = newValue
Hope this helps. www.insteptech.com ;
msmvps.com/blogs/deborahk
We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS! |
| DeborahK Thursday, August 13, 2009 7:18 PM |
Yes... but this does not work for the same situation for minimum change(by ex from 0 to -15, curernt value ).... something like
Dim newValue As Integer = Me.TrackBar1.Value
Me.TrackBar1.Value = Me.TrackBar1.Maximum
Me.TrackBar1.Value = Me.TrackBar1.Minimum
Me.TrackBar1.Value = newValue
works... but Really this looks like a bug. I shouldn't "hack" the control in this way... Maybe is there a current BindingUpdate on the form or control?
Best regards, Sergiu - Edited bySergiu Dudnic Friday, August 14, 2009 10:32 AM
- Edited bySergiu Dudnic Friday, August 14, 2009 10:41 AM
-
|
| Sergiu Dudnic Friday, August 14, 2009 10:31 AM |
Since the control apparently doesn't notify anyone of the change in its value, you'll never be able to reflect this change in your binding. You'll need to fix this bug by extending the TrackBar control. None of the members we're talking about are overridable so you'll have to shadow them and hope that nobody casts your control to TrackBar.... : Class MyTrackBar Inherits TrackBar Public Shadows Property Minimum() As Integer Get ...
|
| Michal Burger Friday, August 14, 2009 10:50 AM |
So, if the control itself did not notify the BindingContext, I would like to notify it "myself" Best regards,
Sergiu |
| Sergiu Dudnic Friday, August 14, 2009 11:05 AM |
All you need to do is just call the property setter, it will take care of notifying everyone of the change: Public Shadows Property Minimum() As Integer Get Return MyBase.Minimum End Get Set(ByVal value As Integer) If Me.Value < value Then Me.Value = value End If MyBase.Minimum = value End Set End Property (Do the same thing for Maximum and for SetRange if you plan to use it.) - Marked As Answer bySergiu Dudnic Tuesday, August 18, 2009 10:27 AM
-
|
| Michal Burger Friday, August 14, 2009 11:09 AM |
OK. But what If I can't (wouldn't) change the type of controls usied in my project? Best regards,
Sergiu |
| Sergiu Dudnic Friday, August 14, 2009 11:31 AM |
Then you'll have to update the Value manually as DeborahK suggested. |
| Michal Burger Friday, August 14, 2009 12:03 PM |
And you can log the bug into connect ... though with Microsoft focusing on WPF I doubt that we would see a fix on this any time soon. connect.microsoft.com Hope this helps. www.insteptech.com ;
msmvps.com/blogs/deborahk
We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS! |
| DeborahK Friday, August 14, 2009 3:04 PM |
|
| Sergiu Dudnic Friday, August 14, 2009 3:27 PM |
https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=483012
Best regards, Sergiu
As usual, Microsoft does not consider this issue "critical", and will not fix it.
Best regards, Sergiu - Marked As Answer bySergiu Dudnic Tuesday, August 18, 2009 10:26 AM
-
|
| Sergiu Dudnic Monday, August 17, 2009 9:05 AM |