Compare commits
3 Commits
637271039c
...
a503ccac17
Author | SHA1 | Date | |
---|---|---|---|
a503ccac17 | |||
8db45c48bf | |||
9863bdba24 |
@ -4,7 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WinFormsLibrary1
|
||||
namespace Components.Exceptions
|
||||
{
|
||||
public class UncheckedNullException : Exception
|
||||
{
|
@ -4,7 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WinFormsLibrary1
|
||||
namespace Components.Exceptions
|
||||
{
|
||||
public class UnexpectedTypeException : Exception
|
||||
{
|
@ -1,23 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WinFormsLibrary1
|
||||
{
|
||||
public class User
|
||||
{
|
||||
public string username { get; private set; }
|
||||
public string email { get; private set; }
|
||||
public DateTime birthday { get; private set; }
|
||||
|
||||
public User(string username, string email, DateTime birthday)
|
||||
{
|
||||
this.username = username;
|
||||
this.email = email;
|
||||
this.birthday = birthday;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -4,12 +4,12 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WinFormsLibrary1
|
||||
namespace Components.Visual
|
||||
{
|
||||
public class ColumnInfo
|
||||
{
|
||||
public string HeaderText { get; set; } = string.Empty;
|
||||
public int Width { get; set; }
|
||||
public int Width { get; set; }
|
||||
public bool Visible { get; set; }
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public ColumnInfo(string headerText, string name, int width, bool visible)
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Components.Exceptions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
@ -8,6 +8,7 @@ using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using Components.Visual;
|
||||
|
||||
namespace WinFormsLibrary1
|
||||
{
|
||||
@ -51,9 +52,22 @@ namespace WinFormsLibrary1
|
||||
dataGridViewTable.Rows.Clear();
|
||||
}
|
||||
|
||||
public void AddObjectList(List<object> os)
|
||||
public void AddList<T>(List<T> values)
|
||||
{
|
||||
dataGridViewTable.DataSource = os ?? throw new ArgumentNullException();
|
||||
ClearRows();
|
||||
var props = typeof(T).GetProperties();
|
||||
|
||||
foreach (T value in values)
|
||||
{
|
||||
int newRowInd = dataGridViewTable.Rows.Add();
|
||||
foreach (DataGridViewColumn col in dataGridViewTable.Columns)
|
||||
{
|
||||
var prop = props.FirstOrDefault(x => x.Name == col.Name)
|
||||
?? throw new InvalidOperationException($"No property {col.Name} found in type {typeof(T).Name}");
|
||||
var val = prop.GetValue(value);
|
||||
dataGridViewTable.Rows[newRowInd].Cells[col.Index].Value = val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public T GetObjectFromRow<T>()
|
||||
@ -78,23 +92,5 @@ namespace WinFormsLibrary1
|
||||
}
|
||||
return returnObject;
|
||||
}
|
||||
|
||||
public void AddList<T> (List<T> values)
|
||||
{
|
||||
ClearRows();
|
||||
var props = typeof(T).GetProperties();
|
||||
|
||||
foreach (T value in values)
|
||||
{
|
||||
int newRowInd = dataGridViewTable.Rows.Add(value);
|
||||
foreach (DataGridViewColumn col in dataGridViewTable.Columns)
|
||||
{
|
||||
var prop = props.FirstOrDefault(x => x.Name == col.Name)
|
||||
?? throw new InvalidOperationException($"No property {col.Name} found in type {typeof(T).Name}");
|
||||
var val = prop.GetValue(value);
|
||||
dataGridViewTable.Rows[newRowInd].Cells[col.Index].Value = val;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user