2-Way Binding to a TrackBar Not Working. What is my Problem?

2-Way Binding to a TrackBar Not Working. What is my Problem?

Post by Q29saW » Thu, 14 Oct 2004 16:05:02


I'm trying to bind a TrackBar to an entity object of mine:

myBar.DataBindings.Add( "Value", imgConvData, "Quality" );

It seems simple enough, and the TrackBar does indeed pick up the value of
"Quality" when the DataBinding is first set. Unfortunately, changing the
value of the TrackBar (via sliding the thingie around) doesn't change the
value of "Quality" for some reason. If I bind to a TextBox, on the other
hand, everything works well.

Why won't the TrackBar binding work?
 
 
 

2-Way Binding to a TrackBar Not Working. What is my Problem?

Post by Nathan Bau » Thu, 14 Oct 2004 21:39:10

> I'm trying to bind a TrackBar to an entity object of mine:


I was able to get it working when binding to a DataTable, but not with an
arbitary object like you seem to be doing.
When using the DataTable, it was necessary to call
CurrencyManager.EndCurrentEdit() on ValueChange, as follows:

private void trackBar1_ValueChanged(object sender, EventArgs e)
{
trackBar1.DataBindings["Value"]
.BindingManagerBase.EndCurrentEdit();
}

However when trying this with an object (in which case a PropertyManager
would be used), it didn't work at all.
The weird thing is that both EndCurrentEdit() implementations are almost
identical when disassembling.
Have you tried EndCurrentEdit()?

 
 
 

2-Way Binding to a TrackBar Not Working. What is my Problem?

Post by Q29saW » Fri, 15 Oct 2004 13:09:02

Nathan,

Love ya! It worked for me.

Any word on the mechanics of why I need to call EndCurrentEdit for a
TrackBar when I don't with a TextBox?

I'm a web programmer, so this Windows stuff is still pretty new to me.
 
 
 

2-Way Binding to a TrackBar Not Working. What is my Problem?

Post by Nathan Bau » Fri, 15 Oct 2004 15:20:22

> Any word on the mechanics of why I need to call EndCurrentEdit for a

I'm not sure. In my testing I needed EndCurrentEdit() for TextBoxes as well!
 
 
 

2-Way Binding to a TrackBar Not Working. What is my Problem?

Post by Q29saW » Fri, 15 Oct 2004 17:43:01

Weird.

Okay, now I have a new problem. I now have my property ("Height")
synchronized with the TrackBars, but the "Height" property is also bound to a
TextBox.

The problem: If I change the TextBox value, the TrackBar value will change
appropriately, but if I change the TrackBar, the TextBox doesn't get updated.

I communicate my class changes with an HeightChanged event as a tutorial
suggested (and actually both the TextBox and the TrackBar values get set if I
change "Height" programmatically), but the TrackBar isn't communicating
changes properly. Any ideas?