Is there an event that I can latch onto to be notified when the datasource has been applied to its bound controls?
Or is there another event, in which I am guaranteed that the data-source has been applied?
I'm working with WinForms (coming from WPF) and am using tags with data-bound values in order to determine the type of control I'm working with. Many controls could have the same tag value, and I must retrieve the controls with the desired tag in order to perform business logic.
The problem is that I do not know when to perform my search for the tag values. I've attempted to search for the tag values immediately after calling:
myBindingSource.DataSource = OutputFunctions.Instance;
//Yes... I'm binding to a singleton with a list of properties.
//Its not the best method, but works.
inside my Form.Load
event handler. But, during the search, I've seen that the tag values are not set. How can this be if I've just set the data source?
As can be seen from the internally managed code-behind for my form, I have properly set the value through the designer's Property window:
this.textBoxDTemp.DataBindings.Add(new System.Windows.Forms.Binding(
"Tag",
this.myBindingSource,
"KNOB_DRIVER_TEMP",
true));
I've taken a look at the BindingComplete
, which honestly looks very promising, except that it doesn't trigger during the initialization of the binding, even though the value supposedly is propagating from the data-source to the target control.
EDIT:
Per requested, the data-source is first set in the internal code-behind for the form as such:
this.myBindingSource.DataSource = typeof(OutputFunctions);
And here is the singleton in case it helps.
public class OutputFunctions
{
private static OutputFunctions instance;
public static OutputFunctions Instance
{
get
{
if (instance == null)
{
instance = new OutputFunctions();
}
return instance;
}
}
private OutputFunctions() { }
public string KNOB_DRIVER_TEMP { get { return "KNOB_DRIVER_TEMP"; } }
public string KNOB_PASSENGER_TEMP { get { return "KNOB_PASSENGER_TEMP"; } }
public string KNOB_FAN { get { return "KNOB_FAN"; } }
}
See Question&Answers more detail:
os