Data Binding

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I have a TextBox on ToolStrip. The TextBox name is:
toolStripTextBoxTorch.
I have a BindingList defined as:
public BindingList<ChannelConfigData> blistChannelConfigData;

ChannelConfigData has an integer member: nTorch.

I am trying to bind the toolStripTextBoxTorch TextBox to the value of the
nTorch.

Any Idea how do I do that?

Thanks,
Eitan
 
Hello,

I have a TextBox on ToolStrip. The TextBox name is:
toolStripTextBoxTorch.
I have a BindingList defined as:
public BindingList<ChannelConfigData> blistChannelConfigData;

ChannelConfigData has an integer member: nTorch.

I am trying to bind the toolStripTextBoxTorch TextBox to the value of the
nTorch.

Any Idea how do I do that?

Thanks,
Eitan

Hi Eitan,

toolStripTextBox1.TextBox.DataBindings.Add("Text", blistChannelConfigData, "Torch", false, DataSourceUpdateMode.OnPropertyChanged);

Wether or not you want to update on propertychanged is up to you.
Note, "Torch" is actually a property updating its underlying member nTorch. Databindings can only be done with properties.

To have the databinding update other controls bound to the BindingList as well you need to implement INotifyPropertyChanged on the ChannelCOnfigData class

public class ChannelConfigData : INotifyPropertyChanged
{
private int nTorch;

public int Torch
{
get { return nTorch; }
set
{
nTorch = value;
notifyPropertyChanged("Torch");
}
}

public ChannelConfigData(int torch)
{
Torch = torch;
}

#region INotifyPropertyChanged Members

public event PropertyChangedEventHandler PropertyChanged;

#endregion

private void notifyPropertyChanged(string property)
{
if(PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(property));
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top