Datagridview
get
set
ColumnX ColumnY Name Join Age 18 Location LA
Person
Person _person = null; private class Person { private string Name {get;set;} private int Age {get;set;} private string Location {get;set} } private void GridviewToObject() { Person _person = new Person(); for (int i = 0; i < dgv_gridview.Rows.Count; i++) { if (dgv_gridview.Rows[i].Cells[0].Value.ToString() == "Name") { _person.Name = dgv_gridview.Rows[i].Cells[1].Value.ToString(); } if (dgv_gridview.Rows[i].Cells[0].Value.ToString() == "Age") { _person.Age = dgv_gridview.Rows[i].Cells[1].Value.ToString(); } if (dgv_gridview.Rows[i].Cells[0].Value.ToString() == "Location") { _person.Location = dgv_gridview.Rows[i].Cells[1].Value.ToString(); } } } private void bt_test_Click(object sender, EventArgs e) { var _nameperson = _person.Name; //Join var _ageperson = _person.Age; //18 var _locationperson = _person.Location //LA }
_person
GridviewToObject
Age
DateOfBirth
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)