Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm Data Binding / October 2004

Tip: Looking for answers? Try searching our database.

New Problem With TrackBar Binding

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Colin - 14 Oct 2004 09:45 GMT
I'm re-posting this to make sure it gets picked up by support because the
related question was answered:

I have an entity object (not a collection) with a property "Height". It's
bound to a TrackBar and a TextBox. I found out that I needed to call
BindingManagerBase.EndCurrentEdit() on the TrackBar's DataBinding to actually
communicate the TrackBar's change to my object.

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 a 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 update isn't
communicating changes to the TextBox. Any ideas?

For more on what I'm doing, see my 10/13 post.
Sijin Joseph - 14 Oct 2004 13:16 GMT
Can you post some code?

Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph

> I'm re-posting this to make sure it gets picked up by support because the
> related question was answered:
[quoted text clipped - 13 lines]
>
> For more on what I'm doing, see my 10/13 post.
Colin - 14 Oct 2004 18:25 GMT
The exact code is at home, but it's basically set up like this (I'm just
typing this out, so it probably won't compile):

//***********entity class***********************
public event EventHandler HeightChanged;

public virtual void OnHeightChanged( EventArgs e )
{
   if( HeightChanged != null )
       HeightChanged( this, e );
}

private int height;

public int Height
{
 get{ return Height; }
 set
 {
     if( 0 < value || value <= 100 )
          height = value;
     else
          thrown new ArgumentException( "value" );
 }
}

//****************form********************

//initialization
myTrackBar.DataBindings.Add( "Value", myObj, "Height" );
myTextBox.DataBindings.Add( "Text", myObj, "Height" );

//event handler later
protected void myTrackBar_ValueChanged( ... )
{
      myTrackBar.DataBindings["Value"].BindingManagerBase.EndCurrentEdit();
}

> Can you post some code?
>
[quoted text clipped - 19 lines]
> >
> > For more on what I'm doing, see my 10/13 post.
Sijin Joseph - 15 Oct 2004 04:35 GMT
Where are you firing the HeightChanged event when the height is changing?

try this

public event EventHandler HeightChanged;

public virtual void OnHeightChanged( EventArgs e )
{
    if( HeightChanged != null )
        HeightChanged( this, e );
}

private int height;

public int Height
{
  get{ return Height; }
  set
  {
      if( 0 < value || value <= 100 )
    {
           height = value;
      OnHeightChanged(new EventArgs());
    }
      else
           thrown new ArgumentException( "value" );
  }
}

Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph

> The exact code is at home, but it's basically set up like this (I'm just
> typing this out, so it probably won't compile):
[quoted text clipped - 57 lines]
>>>
>>>For more on what I'm doing, see my 10/13 post.
Colin - 15 Oct 2004 08:59 GMT
Thanks again for the reply.

I actually DO fire the HeightChanged event when the Height property changes
in a manner similar to your example, I just forgot to add it in my hasty
typing (whoopsie).

I must emphasize that the event fires properly: a change to the TextBox will
be reflected by the bound TrackBar, and programatically setting the entity
property will cause BOTH the TextBox AND TrackBar to adopt the proper values.
The problem is that the TrackBar JUST ISN'T communicating its changes
properly and it's driving me nuts!!!

I keep trying work-arounds (using .EndCurrentEdit(), manually setting the
property in the TrackBar event handler, etc) but each presents new
coordination problems to overcome and that's something a DataBinding system
(that actually works) would solve.

I'm beginning to feel that this is just a Microsoft bug and have heard of
people having success moving each property to a collection then use THAT for
binding (which is wasteful, but if it works...) so I'm tempted just to throw
in the towel on the non-collection binding unless you (or the MSDN consierge)
have further input.

> Where are you firing the HeightChanged event when the height is changing?
>
[quoted text clipped - 90 lines]
> >>>
> >>>For more on what I'm doing, see my 10/13 post.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.