diff --git a/VisualComponentsForm/VisualComponentsForm/FormMain.cs b/VisualComponentsForm/VisualComponentsForm/FormMain.cs index 3b6bc8a..7049bac 100644 --- a/VisualComponentsForm/VisualComponentsForm/FormMain.cs +++ b/VisualComponentsForm/VisualComponentsForm/FormMain.cs @@ -8,7 +8,7 @@ namespace VisualComponentsForm private int numberObject; private List nameCol = new List { "Номер", "Имя", "Фамилия", "Возраст" }; - private List widthCol = new List { 30, 30, 30, 30 }; + private List widthCol = new List { 60, 60, 60, 60 }; private List showCol = new List { true, true, true, true }; private List nameField = new List { "Id", "Name", "Surname", "Age" }; private List peoples; @@ -20,9 +20,9 @@ namespace VisualComponentsForm peoples = new List { new People(0, "Никита", "Сергеев", 20), - new People(0, "Дарья", "Балберова", 20), - new People(0, "Данил", "Малин", 20), - new People(0, "Николай", "Распаев", 20) + new People(1, "Дарья", "Балберова", 19), + new People(2, "Данил", "Малин", 25), + new People(3, "Николай", "Распаев", 23) }; InitializeComponent(); @@ -81,6 +81,12 @@ namespace VisualComponentsForm myDataGridView.AddObject(peoples[numberObject]); numberObject++; + + if (numberObject == 4) + { + numberObject = 0; + } + } } } \ No newline at end of file diff --git a/VisualComponentsLib/MyDataGridView.cs b/VisualComponentsLib/MyDataGridView.cs index bd7d382..808d581 100644 --- a/VisualComponentsLib/MyDataGridView.cs +++ b/VisualComponentsLib/MyDataGridView.cs @@ -38,12 +38,13 @@ namespace VisualComponentsLib //публичный параметризованный метод для добавления РЅРѕРІРѕРіРѕ объекта РІ СЃРїРёСЃРѕРє public void AddObject(T newObject) { - DataGridViewRow row = new DataGridViewRow(); + DataGridViewRow row = (DataGridViewRow)dataGridView.Rows[0].Clone(); foreach (var prop in newObject.GetType().GetProperties()) { object value = prop.GetValue(newObject); - row.Cells[prop.Name].Value = value; + + row.Cells[dataGridView.Columns[prop.Name].Index].Value = value; } dataGridView.Rows.Add(row);