Hi all!
I have a windows form that is bound to a dataset. Using VS 2005 & .NET
Framework Beta 2.
In my dataset I have a colum called Warranty that is a smallint on SQL
Server 2000(SP4).
What I am trying to do is Parse and Format the value based on choice from
radio buttons and enetered period.
The 4 radio buttons are to determin period of warranty
Unknown, Lifetime, Months, Years
Unknown is DBNull
Lifetime is 0
any negative value means months
Years are posotive values
Here is the code I have hooked up so far for the Parse and Format Events:
#region Warranty Format and Parse Events
private void FormatWarranty(object sender, ConvertEventArgs cevent)
{
if (cevent.DesiredType != typeof(System.Decimal))
{
return;
}
if (cevent.Value == System.DBNull.Value)
{
this.radioButtonUnknown.Checked = true;
this.numericUpDownWarranty.Enabled = false;
cevent.Value = System.DBNull.Value;
}
else if (Convert.ToDecimal(cevent.Value) < 0)
{
cevent.Value = Convert.ToDecimal(Math.Abs(
Convert.ToInt16(cevent.Value)));
this.radioButtonMonths.Checked = true;
this.numericUpDownWarranty.Enabled = true;
}
else if (Convert.ToDecimal(cevent.Value) == 0)
{
this.radioButtonLifetime.Checked = true;
this.numericUpDownWarranty.Enabled = false;
cevent.Value = Convert.ToDecimal(cevent.Value);
}
else
{
this.radioButtonYears.Checked = true;
this.numericUpDownWarranty.Enabled = true;
cevent.Value = Convert.ToDecimal(cevent.Value);
}
}
private void ParseWarranty(object sender, ConvertEventArgs cevent)
{
if (cevent.DesiredType != typeof(System.Int16))
{
return;
}
if (this.radioButtonUnknown.Checked)
{
cevent.Value = System.DBNull.Value;
}
else if (this.radioButtonLifetime.Checked)
{
cevent.Value = Convert.ToInt16(0);
}
else if (this.radioButtonMonths.Checked)
{
cevent.Value = Convert.ToInt16("-" +
this.numericUpDownWarranty.Value.ToString());
}
else if (this.radioButtonYears.Checked)
{
cevent.Value = Convert.ToInt16(this.numericUpDownWarranty.Value);
}
}
#endregion
When setting cevent.Value property the data is not being updated when I do
the call the dataset update method.
Any ideas, have I done this all wrong?
Paul