Re: Type convertsion from string
- From: Jon Skeet [C# MVP] <skeet@xxxxxxxxx>
- Date: Mon, 15 Oct 2007 19:23:05 +0100
Andrus <kobruleht2@xxxxxx> wrote:
Using VCS 2005 Express .NET 2 WinForms.
I implemented entity databinding in DataGridView OnCellValuePushed method as
PropertyInfo p = entityTmp.GetType().GetProperty(
Columns[e.ColumnIndex].DataPropertyName);
// e.Value type is string
p.SetValue(entityTmp, e.Value, null);
This works only for string property types.
For other types SetValue() causes System.ArgumentException like
Object of type 'System.String' cannot be converted to type 'System.Decimal'.
How to change this code so that SetValue() works for non-string types ?
I need to convert string type (e.Value) to property type:
How to convert string to property p type ?
Have you tried Convert.ChangeType?
--
Jon Skeet - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
.
- Follow-Ups:
- Re: Type convertsion from string
- From: Andrus
- Re: Type convertsion from string
- References:
- Type convertsion from string
- From: Andrus
- Type convertsion from string
- Prev by Date: Re: Regex with double and char
- Next by Date: Allow to reference to any version of assembly during compiling
- Previous by thread: Type convertsion from string
- Next by thread: Re: Type convertsion from string
- Index(es):