diff --git a/KopLab1/FormLibrary/ValueTableControl.cs b/KopLab1/FormLibrary/ValueTableControl.cs index 778c3e6..2e582b1 100644 --- a/KopLab1/FormLibrary/ValueTableControl.cs +++ b/KopLab1/FormLibrary/ValueTableControl.cs @@ -52,7 +52,7 @@ namespace FormLibrary public int SelectedRowIndex { - get => dataGridView1.SelectedRows.Count > 0 ? dataGridView1.SelectedRows[0].Index : -1; + get => dataGridView1.SelectedRows[0].Index; set { if (value >= 0 && value < dataGridView1.Rows.Count) @@ -74,7 +74,7 @@ namespace FormLibrary foreach (DataGridViewColumn column in dataGridView1.Columns) { var prop = typeof(T).GetProperty(column.DataPropertyName); - if (prop != null && prop.CanWrite) + if (prop != null) { var value = selectedRow.Cells[column.Index].Value; prop.SetValue(obj, Convert.ChangeType(value, prop.PropertyType)); @@ -84,15 +84,24 @@ namespace FormLibrary return obj; } - public void FillData(List students) + public void FillData(List objects) { - dataGridView1.DataSource = null; dataGridView1.Rows.Clear(); - foreach (var student in students) + if (objects == null || !objects.Any()) { - dataGridView1.Rows.Add(student.Group, student.FullName, student.Course); + return; + } + + var properties = typeof(T).GetProperties(); + + foreach (var obj in objects) + { + var values = properties.Select(p => p.GetValue(obj, null)).ToArray(); + dataGridView1.Rows.Add(values); } } + + } }