lundi 13 novembre 2017

Setting a property value by reflection from DataGridView value

I've a DataGridView, and I want to change collection who connect to this list when cell value has been changed, using CellEndEdit event:

var p = wareList[e.RowIndex].GetType().GetProperties()[e.ColumnIndex];

object value = dataGreadView[e.ColumnIndex, e.RowIndex].Value;

p.SetValue(typeof(Ware), Convert.ChangeType(value, p.PropertyType));

But at the last line I got exeption System.Reflection.TargetException: "The object does not match the end type."





Aucun commentaire:

Enregistrer un commentaire