2023-09-13 11:57:01 +04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace VisualComponentsLib
|
|
|
|
|
{
|
2023-09-13 13:48:16 +04:00
|
|
|
|
public partial class MyDataGridView : UserControl
|
2023-09-13 11:57:01 +04:00
|
|
|
|
{
|
2023-09-13 13:48:16 +04:00
|
|
|
|
public MyDataGridView()
|
2023-09-13 11:57:01 +04:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
2023-09-13 12:53:53 +04:00
|
|
|
|
|
2023-09-27 00:31:17 +04:00
|
|
|
|
//публичный метод создания заголовков таблицы
|
|
|
|
|
public void AddHeader(int countCol, List<string> nameCol, List<int> widthCol,
|
|
|
|
|
List<bool> showCol, List<string> nameField)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < countCol; i++)
|
|
|
|
|
{
|
|
|
|
|
DataGridViewColumn textColumn = new DataGridViewColumn();
|
|
|
|
|
|
|
|
|
|
textColumn.Name = nameCol[i];
|
|
|
|
|
textColumn.HeaderText = nameField[i];
|
|
|
|
|
textColumn.Width = widthCol[i];
|
|
|
|
|
textColumn.Visible = showCol[i];
|
|
|
|
|
textColumn.CellTemplate = new DataGridViewTextBoxCell();
|
|
|
|
|
|
|
|
|
|
dataGridView.Columns.Add(textColumn);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//публичный параметризованный метод для добавления нового объекта в список
|
|
|
|
|
public void AddObject<T>(T newObject)
|
2023-09-13 12:53:53 +04:00
|
|
|
|
{
|
2023-09-27 00:51:33 +04:00
|
|
|
|
DataGridViewRow row = new DataGridViewRow();
|
2023-09-13 12:53:53 +04:00
|
|
|
|
|
2023-09-27 00:51:33 +04:00
|
|
|
|
foreach (var prop in newObject.GetType().GetProperties())
|
|
|
|
|
{
|
|
|
|
|
row.Cells[prop.ToString()].Value = prop.GetValue(newObject);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dataGridView.Rows.Add(row);
|
2023-09-13 12:53:53 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//полная очистка
|
2023-09-27 00:31:17 +04:00
|
|
|
|
public void ClearTable()
|
2023-09-13 12:53:53 +04:00
|
|
|
|
{
|
|
|
|
|
dataGridView.Rows.Clear();
|
|
|
|
|
}
|
2023-09-13 11:57:01 +04:00
|
|
|
|
}
|
|
|
|
|
}
|