Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > trackbar databinding
 

trackbar databinding

I need to bind a trackbar value with an integer that I have, which is constantly changing. How can I do that?
aherlambang  Tuesday, July 21, 2009 1:44 AM
Hi aherlambang,

You need to wrap it into a class in order to use DataBinding. That class should implement INotifyPropertyChanged interface. Here is the example.
public class MyInteger : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private int intValue;
public int IntValue
{
get { return intValue; }
set
{
intValue = value;
PropertyChanged(this, new PropertyChangedEventArgs("IntValue"));
}
}

public MyInteger()
{
PropertyChanged = new PropertyChangedEventHandler(OnPropertyChanged);
intValue = 0;
}

protected void OnPropertyChanged(object send, PropertyChangedEventArgs e)
{
}
}

To use this class in DataBinding.
MyInteger myInt = new MyInteger();
myInt.IntValue = 1;
trackBar1.DataBindings.Add("Value", myInt, "IntValue");

Sincerely,
Kira Qian
Please mark the replies as answers if they help and unmark if they don't.
Kira Qian  Wednesday, July 22, 2009 7:35 AM
Hi aherlambang,

You need to wrap it into a class in order to use DataBinding. That class should implement INotifyPropertyChanged interface. Here is the example.
public class MyInteger : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private int intValue;
public int IntValue
{
get { return intValue; }
set
{
intValue = value;
PropertyChanged(this, new PropertyChangedEventArgs("IntValue"));
}
}

public MyInteger()
{
PropertyChanged = new PropertyChangedEventHandler(OnPropertyChanged);
intValue = 0;
}

protected void OnPropertyChanged(object send, PropertyChangedEventArgs e)
{
}
}

To use this class in DataBinding.
MyInteger myInt = new MyInteger();
myInt.IntValue = 1;
trackBar1.DataBindings.Add("Value", myInt, "IntValue");

Sincerely,
Kira Qian
Please mark the replies as answers if they help and unmark if they don't.
Kira Qian  Wednesday, July 22, 2009 7:35 AM

You can use google to search for other answers

Custom Search

More Threads

• Issue with custom datagridview column
• Create a dataview using criteria from a child table.
• DataGridView ComboBox validating problem
• Copy & Paste functions in datagrid?
• To query a query
• VB 2005: db connection string
• generation a typed dataset from a database
• how to bind an array of string with DataGridView ?
• Datagridview Clear Cell Values on Space key press
• Datagrid event for cell content change?