Two components are fixed, but the third one...
This commit is contained in:
parent
d1b89209ef
commit
9108f2f86c
31
CustomComponents/Classes/ColumnConfiguration.cs
Normal file
31
CustomComponents/Classes/ColumnConfiguration.cs
Normal file
@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CustomComponents.Classes
|
||||
{
|
||||
|
||||
public class ColumnConfiguration
|
||||
{
|
||||
public int ColumnsQuantity { get; private set; }
|
||||
|
||||
public List<string> Headers { get; private set; } = new();
|
||||
|
||||
public List<int> ColumnWidth { get; private set; } = new();
|
||||
|
||||
public List<bool> Visibility { get; private set; } = new();
|
||||
|
||||
public List<string> ColumnName { get; private set; } = new();
|
||||
|
||||
public ColumnConfiguration(int columnsQuantity, List<string> headers, List<int> columnWidth, List<bool> visibility, List<string> columnName)
|
||||
{
|
||||
ColumnsQuantity = columnsQuantity;
|
||||
Headers = headers;
|
||||
ColumnWidth = columnWidth;
|
||||
Visibility = visibility;
|
||||
ColumnName = columnName;
|
||||
}
|
||||
}
|
||||
}
|
@ -9,6 +9,7 @@ using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Dynamic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@ -25,13 +26,13 @@ namespace CustomComponents
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public void ColumnConfiguration(int columnsQuantity, List<string> headers, List<int> columnWidth, List<bool> visibility, List<string> columnName)
|
||||
public void ColumnConfiguration(ColumnConfiguration config)
|
||||
{
|
||||
for (int i = 0; i < columnsQuantity; i++)
|
||||
for (int i = 0; i < config.ColumnsQuantity; i++)
|
||||
{
|
||||
customGridView.Columns.Add(headers.ElementAt(i), columnName.ElementAt(i));
|
||||
customGridView.Columns[i].Width = columnWidth.ElementAt(i);
|
||||
customGridView.Columns[i].Visible = visibility.ElementAt(i);
|
||||
customGridView.Columns.Add(config.Headers.ElementAt(i), config.ColumnName.ElementAt(i));
|
||||
customGridView.Columns[i].Width = config.ColumnWidth.ElementAt(i);
|
||||
customGridView.Columns[i].Visible = config.Visibility.ElementAt(i);
|
||||
}
|
||||
}
|
||||
|
||||
@ -56,32 +57,38 @@ namespace CustomComponents
|
||||
|
||||
public void AddRows<T>(List<T> objects)
|
||||
{
|
||||
var type = objects.GetType();
|
||||
var fields = type.GetProperties();
|
||||
var type = typeof(T);
|
||||
var props = type.GetProperties();
|
||||
|
||||
|
||||
foreach (var obj in objects)
|
||||
{
|
||||
List<object> values = new();
|
||||
values.AddRange(obj.GetType().GetProperties().Select(prop => prop.GetValue(obj)));
|
||||
|
||||
DataGridViewRow row = new DataGridViewRow();
|
||||
row.CreateCells(customGridView);
|
||||
|
||||
|
||||
|
||||
int columnIndex = 0;
|
||||
foreach(var value in values)
|
||||
int propertyIndex = 0;
|
||||
foreach (var value in values)
|
||||
{
|
||||
var prop = props.ElementAt(propertyIndex++);
|
||||
columnIndex = customGridView.Columns[prop.Name].Index;
|
||||
|
||||
if (!(value is string) && typeof(IEnumerable).IsAssignableFrom(value.GetType()))
|
||||
{
|
||||
row.Cells[columnIndex].Value = EnumerableConverter(value);
|
||||
customGridView.Rows[0].Cells[columnIndex].Value = EnumerableConverter(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
row.Cells[columnIndex].Value = value;
|
||||
customGridView.Rows[0].Cells[columnIndex].Value = value;
|
||||
}
|
||||
columnIndex++;
|
||||
|
||||
}
|
||||
customGridView.Rows.Add(row);
|
||||
|
||||
if (!obj.Equals(objects.Last()))
|
||||
{
|
||||
customGridView.Rows.Add();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,9 +3,6 @@
|
||||
public partial class Frame : UserControl
|
||||
{
|
||||
|
||||
|
||||
private string? SelectedValue = string.Empty;
|
||||
|
||||
public event EventHandler ValueChanged;
|
||||
|
||||
public Frame()
|
||||
@ -35,18 +32,18 @@
|
||||
{
|
||||
return "";
|
||||
}
|
||||
return SelectedValue;
|
||||
return listBox.SelectedItem.ToString();
|
||||
}
|
||||
set
|
||||
{
|
||||
SelectedValue = value;
|
||||
listBox.SelectedItem = listBox.Items.IndexOf(!string.IsNullOrEmpty(value) ? Convert.ToInt32(value) : -1);
|
||||
}
|
||||
}
|
||||
|
||||
private void SelectedValue_Changed(object sender, EventArgs e)
|
||||
{
|
||||
var element = sender as ListBox;
|
||||
Value = element.Text.ToString();
|
||||
Value = element.SelectedIndex.ToString();
|
||||
ValueChanged?.Invoke(this, e);
|
||||
}
|
||||
}
|
||||
|
@ -13,16 +13,25 @@ namespace CustomComponents
|
||||
{
|
||||
public partial class frameTextBox : UserControl
|
||||
{
|
||||
private string? _text;
|
||||
private int? _text;
|
||||
public string Error { get; private set; }
|
||||
|
||||
public event EventHandler taskHandler;
|
||||
private event Action? _errorOccured;
|
||||
|
||||
public event Action AnErrorOccurred
|
||||
{
|
||||
add { _errorOccured += value; }
|
||||
remove { _errorOccured -= value; }
|
||||
}
|
||||
|
||||
public frameTextBox()
|
||||
{
|
||||
InitializeComponent();
|
||||
Error = string.Empty;
|
||||
}
|
||||
|
||||
public string? Value
|
||||
public int? Value
|
||||
{
|
||||
get
|
||||
{
|
||||
@ -42,7 +51,7 @@ namespace CustomComponents
|
||||
{
|
||||
textBox.Enabled = false;
|
||||
|
||||
if (!string.IsNullOrEmpty(_text))
|
||||
if (!string.IsNullOrEmpty(textBox.Text))
|
||||
{
|
||||
throw new ContentException(true);
|
||||
}
|
||||
@ -50,7 +59,7 @@ namespace CustomComponents
|
||||
else
|
||||
{
|
||||
textBox.Enabled = true;
|
||||
if (string.IsNullOrEmpty(_text))
|
||||
if (string.IsNullOrEmpty(textBox.Text))
|
||||
{
|
||||
throw new ContentException(false);
|
||||
}
|
||||
@ -58,6 +67,9 @@ namespace CustomComponents
|
||||
}
|
||||
catch(ContentException ex)
|
||||
{
|
||||
Error = ex.Message;
|
||||
_errorOccured?.Invoke();
|
||||
|
||||
HandlerCreation(ex.Message);
|
||||
}
|
||||
taskHandler?.Invoke(this, e);
|
||||
@ -66,20 +78,23 @@ namespace CustomComponents
|
||||
|
||||
private void CheckTextBoxValueType(object sender, EventArgs e)
|
||||
{
|
||||
Value = textBox.Text;
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
if(!Value.All(char.IsDigit))
|
||||
if(!textBox.Text.All(char.IsDigit))
|
||||
{
|
||||
throw new NotIntegerException(Value);
|
||||
throw new NotIntegerException(textBox.Text);
|
||||
}
|
||||
Value = Convert.ToInt32(textBox.Text);
|
||||
}
|
||||
catch (NotIntegerException ex)
|
||||
{
|
||||
Value = null;
|
||||
HandlerCreation(ex.Message);
|
||||
}
|
||||
taskHandler?.Invoke(this, e);
|
||||
|
||||
}
|
||||
|
||||
private void HandlerCreation(string message)
|
||||
|
@ -23,11 +23,11 @@ namespace TestForms
|
||||
|
||||
private void buttonConfigureGridView_Click(object sender, EventArgs e)
|
||||
{
|
||||
frameCustomGridView1.ColumnConfiguration(5,
|
||||
new List<string>() { "ID", "Login", "LoginTimes", "Town", "Creation" },
|
||||
frameCustomGridView1.ColumnConfiguration(new ColumnConfiguration(5,
|
||||
new List<string>() { "ID", "Login", "LoginTimes", "Town", "CreationDate" },
|
||||
new List<int>() { 80, 80, 80, 80, 80 },
|
||||
new List<bool> { true, true, true, true, true },
|
||||
new List<string> { "ID", "Login", "LoginTimes", "Town", "Creation" });
|
||||
new List<string> { "ID", "Login", "LoginTimes", "Town", "CreationDate" }));
|
||||
buttonConfigureGridView.Visible = false;
|
||||
fillGridViewButton.Visible = true;
|
||||
getSelectedRowButton.Visible = true;
|
||||
@ -38,9 +38,10 @@ namespace TestForms
|
||||
{
|
||||
frameCustomGridView1.AddRows(new List<Account>()
|
||||
{
|
||||
new Account(1,"boba","idk"),
|
||||
new Account(2,"biba","idk"),
|
||||
new Account(3,"buba","idk")
|
||||
new Account(1,"boba","crt"),
|
||||
new Account(2,"biba","msp"),
|
||||
new Account(3,"buba","trs"),
|
||||
new Account(4,"byba","pog")
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user