You can do this with PropertyInfo.SetValue().
In this example, I added an explanation that all this does.
I used the class TestClassfor this example. First I get the type.
var type = typeof(TestClass);
PropertyInfo, , .
var properties = new Dictionary<string, PropertyInfo>();
foreach (DataGridViewColumn col in dataGridView1.Columns)
{
properties.Add(col.Name, type.GetProperty(col.Name));
}
.
foreach (DataGridViewRow item in dataGridView1.Rows)
{
if (Convert.ToBoolean( item.Cells[0].Value) == true)
{
TestClass.
var instance = new TestClass();
foreach (DataGridViewColumn col in dataGridView1.Columns)
{
SetValue, . , , , .
object value = Convert.ChangeType(item.Cells[col.Name].Value, properties[col.Name].PropertyType);
properties[col.Name].SetValue(instance, value, null);
}
, .
Collection.Add(instance);
}
}