Hi Ying-Shen,
I apologize. The problem is a bit different than I explained. It occurs
when I create a new DataSet and databind it to the controls - not loading an
existing dataset. So, the DataSet initially does not have any values.
I just tried this... If I load a new DataSet, save it, and bring it up in
the UI it will not contain any of the default values. Most likely it is the
delayed initialization that is causing the problem. At what point does the
data get into the DataSet? When the window is shown?
It sounds like I will have to explicitely initialize all the controls. Is
this true?
To follow up on your questions:
There are no exceptions being thrown. I turned on breaking when an
exception is thrown as you suggested. Here is the code for the validation
handler. (NotifyParent() is kind of a kludge to prevent the tab switch -
just sends a custom message to the main window)
private void OnValidateDouble(object sender,
System.ComponentModel.CancelEventArgs e)
{
if ( sender.GetType() != typeof(DoubleTextBox) )
return;
DoubleTextBox tb = (DoubleTextBox)sender;
if ( tb.Text.Trim() == String.Empty )
{
double temp = Math.Round(tb.DefaultValue, ROUND_LEN);
tb.Text = temp.ToString();
if ( !_allowBlank )
{
tb.SelectAll();
e.Cancel = true;
NotifyParent(false);
}
NotifyParent(true);
return;
}
double dVal;
try
{
dVal = Convert.ToDouble(tb.Text);
}
catch ( Exception ex )
{
MessageBox.Show(this, ex.Message, "You must enter a number");
double temp = Math.Round(tb.DefaultValue, ROUND_LEN);
tb.Text = temp.ToString();
e.Cancel = true;
NotifyParent(false);
return;
}
tb.MinimumValue = Math.Round(tb.MinimumValue, ROUND_LEN);
tb.MaximumValue = Math.Round(tb.MaximumValue, ROUND_LEN);
if ( dVal < tb.MinimumValue || dVal > tb.MaximumValue )
{
StringBuilder builder = new StringBuilder();
builder.Append("Maximum value: ");
builder.Append(this.MaximumValue);
builder.Append("\nMinimum value: ");
builder.Append(this.MinimumValue);
MessageBox.Show(this, builder.ToString(), "Value out of range");
double temp = Math.Round(tb.DefaultValue, ROUND_LEN);
tb.Text = temp.ToString();
tb.SelectAll();
NotifyParent(false);
e.Cancel = true;
}
NotifyParent(true);
}
private void NotifyParent(bool status)
{
if ( _parentForm != null )
{
// if the validation fails, the focus will return to the control
// validation will occur a second time before a tab change event is
fired
// cancel the second validation notification message so that the tab
will not change
if ( status == true && _previousValidationFailed == true )
{
_previousValidationFailed = false;
return;
}
_previousValidationFailed = true;
// This is just a wrapper around the SendMessage() API function
ValidationHelper.SendMessage(((Form)_parentForm).Handle,
(int)ValidationHelper.VC_ONVALIDATION,
0,
(status == false) ? 0 : 1);
}
}
Thanks for your help.
Alfredo
Ying-Shen Yu said:
Hi Alfredo,
Winform uses delay initialization to reduce the memory and resource
requirements.
However I'm not sure if this issue is caused by the delay initialization.
Could you post your code snippet of the validating handler?
Also I'm suspecting there might be an internal exception happened during tab
switch, could you try enable catching "first-chance exception" in VS.NET
IDE?
You can enable this option using the following steps:
1. In the menu "Debug", select "Exceptions" to open the Exceptions dialog.
2. Select "Common Language Runtime Exceptions"
3. In the groupbox "When the exception is thrown", set radio selection to
"Break into the debugger"
4. click ok.
Then run your program with debugger (F5), and repeat the steps to see if the
debugger will break in.
If you have any update to this issue, please feel free to reply this thread.
Thanks!
Best regards,
Ying-Shen Yu [MSFT]
Microsoft Community Support
Get Secure! -
www.microsoft.com/security
This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, please remove the word "online"
before sending mail.