Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Binding To a Win Forms TrackBar

Status
Not open for further replies.

BoulderBum

Programmer
Jul 11, 2002
2,179
US
I'm trying to bind a TrackBar to an entity object of mine:

Code:
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 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?
 
I created a form with a TrackBar on it and a button. in the constructor I call createBulkDataTable(). here's what I did:
Code:
                DataTable dt;
		private void createBulkDataTable ()
		{
			dt = new DataTable();
			dt.Columns.Add("id", typeof(int));
			dt.Columns.Add("quality", typeof(int));

			dt.Rows.Add(new Object[] {1, "10"});

			trackBar1.DataBindings.Add("Value", dt, "quality");
		}

		private void button3_Click(object sender, System.EventArgs e)
		{
			MessageBox.Show(trackBar1.Value.ToString());
			MessageBox.Show(dt.Rows[0][1].ToString());
		}

when I move the trackbar and I press the button the two messages that appear have the same value (so it's behaving correctly). I even tried to set the column type of quality to string thinking that there must be an error there, but it still worked.

post more details about the member to which you bind the trackbar

--------------------------
"two wrongs don't make a right, but three lefts do" - the unknown sage
 
Thanks for the reply.

I'm actually using an entity object with properties which ends up using a PropertyManager instead of a ContextManager (or something). Maybe that's the problem?

What happens if you do this:

Code:
public class MyClass 
{
   private int intQuality;

   public MyClass()
   {
       intQuality = 100;
   }

   public int Quality
   {
      get
      {
          return intQuality;
      }
      set
      {
         if( 0 < value && value <= 100 )
             intQuality = value;
         else
            throw new ArgumentException( "value" );
      }
   }
}

//*******************in code**********************

        MyClass mc;

        private void createClass ()
        {
            mc = new MyClass();

            trackBar1.DataBindings.Add("Value", mc, "Quality");
        }

        private void button3_Click(object sender, System.EventArgs e)
        {
            MessageBox.Show(trackBar1.Value.ToString());
            MessageBox.Show(mc.Quality.ToString());
        }
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top