Compare commits
No commits in common. "a503ccac176c99813b939420be759e98418dfc87" and "637271039c417ba620f85abe6b2b9727906d3361" have entirely different histories.
a503ccac17
...
637271039c
@ -4,12 +4,12 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Components.Visual
|
||||
namespace WinFormsLibrary1
|
||||
{
|
||||
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)
|
@ -4,7 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Components.Exceptions
|
||||
namespace WinFormsLibrary1
|
||||
{
|
||||
public class UncheckedNullException : Exception
|
||||
{
|
@ -4,7 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Components.Exceptions
|
||||
namespace WinFormsLibrary1
|
||||
{
|
||||
public class UnexpectedTypeException : Exception
|
||||
{
|
23
Components/User.cs
Normal file
23
Components/User.cs
Normal file
@ -0,0 +1,23 @@
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,5 +1,4 @@
|
||||
using Components.Exceptions;
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
@ -8,7 +8,6 @@ using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using Components.Visual;
|
||||
|
||||
namespace WinFormsLibrary1
|
||||
{
|
||||
@ -52,22 +51,9 @@ namespace WinFormsLibrary1
|
||||
dataGridViewTable.Rows.Clear();
|
||||
}
|
||||
|
||||
public void AddList<T>(List<T> values)
|
||||
public void AddObjectList(List<object> os)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
dataGridViewTable.DataSource = os ?? throw new ArgumentNullException();
|
||||
}
|
||||
|
||||
public T GetObjectFromRow<T>()
|
||||
@ -92,5 +78,23 @@ 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