Raising "Invalid Property Values" 
Author Message
 Raising "Invalid Property Values"

I already try the suggestion bellow and it works, but how can if I want to
throw
the exception from the TypeConverter Class, I already try to throw it from
the TypeConverter but there is no exception raised.

I want to make like when you enter for example char "p" to a "TabIndex"
property from a button it will raise Invalid Property value with desc "p is
not a valid value for Int32."
I think this exception raised from the Int32Converter Class and not from the
component class.

How can they do this? Can I apply this to my component?

Thank's
Yovi


Quote:
> just raising exception in Property Set{} with string will work like

> Exception e = new Exception("17 is wong value");
> throw(e);

> thank you James



> > Hi All,

> > I want to show "Invalid property value" message box for my property in
my
> > component, like when we enter invalid property value in property window.
I
> > already Assign a TypeConverter class with override IsValid method for
the
> > property.

> > The ovverride IsValid method checked whether the value between 1-16 or
> not?

> > How can I "show Invalid Property Value" message box when user enter
value
> > for example 17 in the property window for my property ?

> > thank's

> > Yovi



Tue, 05 Oct 2004 08:56:43 GMT  
 Raising "Invalid Property Values"
Quote:

> I already try the suggestion bellow and it works, but how can if I
> want to throw
> the exception from the TypeConverter Class, I already try to throw it
> from the TypeConverter but there is no exception raised.

raised from the Int32Converter Class and not

Quote:
> from the component class.

This works for me:

namespace WindowsApplication3 {

public class UserControl1 : System.Windows.Forms.UserControl {

    int MyPropValue;

    [TypeConverterAttribute("WindowsApplication3.MyTypeConverter")]
    public int MyProperty {
        get {
            return MyPropValue;
        }
        set {
            MyPropValue = value;
        }
    }

Quote:
}

public class MyTypeConverter : System.ComponentModel.Int32Converter {

    public override object
ConvertFrom(System.ComponentModel.ITypeDescriptorContext context,
System.Globalization.CultureInfo culture, object value) {

        int intvalue = (int) base.ConvertFrom(context, culture, value) ;

        if (intvalue < 1 || intvalue > 15) throw(new
Exception(value.ToString() + " is not a valid value for " +
context.PropertyDescriptor.Name + " property"));

        return intvalue;

Quote:
}

--
Eduardo A. Morcillo (MS MVP VB)
http://www.domaindlx.com/e_morcillo


Tue, 05 Oct 2004 13:13:16 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Raising Invalid Property Value

2. Property grid control pops up "Invalid property value" message when setting string properties?

3. TCP socket: "accept" failed: Invalid argument

4. Q error "invalid function declaration"

5. "Invalid Address specified to RtlFreeHeap(..)"

6. "Invalid access to memory location" error

7. Win 98 "Invalid Page Fault", works fine on W2K, NT

8. What makes a handle "invalid"?

9. "Invalid column number" ODBC

10. "Invalid descriptor index" generated by GetFieldValue

11. still "lnk error : invalid pdata contribution"

12. "Faking" null in value types

 

 
Powered by phpBB® Forum Software