Hi,
I have a win forms project, for simplicity's sake, lets say that I
have a dataset and a textbox that is bound to a numeric column in the
dataset. I also specified a ConvertEventHandler to format the number
in the textbox.
The problem I have is when I run the app, the very first record the
textbox displays is never formatted correctly (the ConvertEventHandler
is never called, I checked). Navigating to the next and subsequent
records it works fine, the number is formatted as per my procedure.
Is there any reason for this behavior? Why is it that only the first
record is affected and subsequent record navigation works fine?
......databinding code:
private void DataBindControls()
{
textBox1.DataBindings.Add("Text", this.myDataSet,
"MYTABLE.MYCOLUMN");
textBox1.DataBindings["Text"].Format += new
ConvertEventHandler(ToDoubleString);
}
......formatting code:
private void ToDoubleString(object sender, ConvertEventArgs e)
{
if (e.Value.ToString() == string.Empty)
e.Value = DBNull.Value; // Don't format nulls.
else
e.Value = ((double)e.Value).ToString("#,##0.0######");
}
Cheers,
PeterZ