вроде done
This commit is contained in:
parent
b9758bf437
commit
04c84290e6
@ -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<Student> students)
|
||||
public void FillData<T>(List<T> 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user