Re: Type convertsion from string
- From: "Marc Gravell" <marc.gravell@xxxxxxxxx>
- Date: Tue, 16 Oct 2007 15:06:21 +0100
If I enter characters to numeric column I get exception "eee is notThe message seems pretty reasonable to me... I don't know what number
a valid
value for Decimal." at line
object val = p.Converter.ConvertFromString(ctx, propertyValue);
How to fix ?
"eee" represents, either. What exactly do you want it to do? is this
hex? or bad user input? If the latter, catch the exception and tell
the user about it. If the former (hex) write a TypeConverter to do the
job.
Why CanConvertFrom() returns true ?CanConvertFrom doesn't take the value - it simply indicates whether it
is reasonable to try, based purely on the types. Does it make *sense*
to go from a decimal to a string. In this case, yes the TypeConverter
is willing to have a try, but that doesn't guarantee that it will work
given illegal input.
I want to allow users to add calculated columns to table at runtime.Yes it is. But you need to know a range of things from
System.ComponentModel. If this is a requirement, can I suggest
DataTable? It isn't ideal from many OO standpoints, but it supports
this out-of-the-box.
For dynamic property additions (this is *not* trivial), see:
http://groups.google.co.uk/group/microsoft.public.dotnet.languages.csharp/browse_thread/thread/f4d8bb5dcdb82a9f/
However, this doesn't even begin to discuss how you would parse the
expression, i.e. "Age * 2"... so again, I say: look at DataTable... or
Excel. This is not an easy area.
Marc
.
- Follow-Ups:
- Re: Type convertsion from string
- From: Andrus
- Re: Type convertsion from string
- References:
- Type convertsion from string
- From: Andrus
- Re: Type convertsion from string
- From: Jon Skeet [C# MVP]
- Re: Type convertsion from string
- From: Andrus
- Re: Type convertsion from string
- From: Marc Gravell
- Re: Type convertsion from string
- From: Andrus
- Re: Type convertsion from string
- From: Marc Gravell
- Re: Type convertsion from string
- From: Andrus
- Type convertsion from string
- Prev by Date: c# ListView selection change
- Next by Date: Re: import/export of forms, possible?
- Previous by thread: Re: Type convertsion from string
- Next by thread: Re: Type convertsion from string
- Index(es):