Reflection :)
This commit is contained in:
parent
3910b2022e
commit
178a5c90ab
@ -14,6 +14,10 @@ namespace CustomComponents.Classes
|
|||||||
public string Town { get; private set; } = string.Empty;
|
public string Town { get; private set; } = string.Empty;
|
||||||
public DateTime CreationDate { get; private set; } = DateTime.Now;
|
public DateTime CreationDate { get; private set; } = DateTime.Now;
|
||||||
|
|
||||||
|
public Account()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
public Account(int id, string login, string town)
|
public Account(int id, string login, string town)
|
||||||
{
|
{
|
||||||
ID = id;
|
ID = id;
|
||||||
|
@ -54,7 +54,7 @@ namespace CustomComponents
|
|||||||
customGridView.Rows.Clear();
|
customGridView.Rows.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddRow<T>(List<T> objects)
|
public void AddRows<T>(List<T> objects)
|
||||||
{
|
{
|
||||||
var type = objects.GetType();
|
var type = objects.GetType();
|
||||||
var fields = type.GetProperties();
|
var fields = type.GetProperties();
|
||||||
@ -63,7 +63,16 @@ namespace CustomComponents
|
|||||||
{
|
{
|
||||||
List<object> values = new();
|
List<object> values = new();
|
||||||
values.AddRange(obj.GetType().GetProperties().Select(prop => prop.GetValue(obj)));
|
values.AddRange(obj.GetType().GetProperties().Select(prop => prop.GetValue(obj)));
|
||||||
customGridView.Rows.Add(values);
|
|
||||||
|
DataGridViewRow row = new DataGridViewRow();
|
||||||
|
row.CreateCells(customGridView);
|
||||||
|
|
||||||
|
foreach(DataGridViewColumn column in customGridView.Columns )
|
||||||
|
{
|
||||||
|
row.Cells[column.Index].Value = values.First();
|
||||||
|
values.RemoveAt(0);
|
||||||
|
}
|
||||||
|
customGridView.Rows.Add(row);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
75
TestForms/Form1.Designer.cs
generated
75
TestForms/Form1.Designer.cs
generated
@ -32,14 +32,17 @@
|
|||||||
clearButton = new Button();
|
clearButton = new Button();
|
||||||
listBox = new CustomComponents.Frame();
|
listBox = new CustomComponents.Frame();
|
||||||
frameTextBox1 = new CustomComponents.frameTextBox();
|
frameTextBox1 = new CustomComponents.frameTextBox();
|
||||||
|
frameCustomGridView1 = new CustomComponents.frameCustomGridView();
|
||||||
|
buttonConfigureGridView = new Button();
|
||||||
|
fillGridViewButton = new Button();
|
||||||
|
getSelectedRowButton = new Button();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// fillButton
|
// fillButton
|
||||||
//
|
//
|
||||||
fillButton.Location = new Point(153, 14);
|
fillButton.Location = new Point(175, 19);
|
||||||
fillButton.Margin = new Padding(3, 2, 3, 2);
|
|
||||||
fillButton.Name = "fillButton";
|
fillButton.Name = "fillButton";
|
||||||
fillButton.Size = new Size(82, 22);
|
fillButton.Size = new Size(94, 29);
|
||||||
fillButton.TabIndex = 1;
|
fillButton.TabIndex = 1;
|
||||||
fillButton.Text = "FILL";
|
fillButton.Text = "FILL";
|
||||||
fillButton.UseVisualStyleBackColor = true;
|
fillButton.UseVisualStyleBackColor = true;
|
||||||
@ -47,10 +50,9 @@
|
|||||||
//
|
//
|
||||||
// clearButton
|
// clearButton
|
||||||
//
|
//
|
||||||
clearButton.Location = new Point(153, 56);
|
clearButton.Location = new Point(175, 75);
|
||||||
clearButton.Margin = new Padding(3, 2, 3, 2);
|
|
||||||
clearButton.Name = "clearButton";
|
clearButton.Name = "clearButton";
|
||||||
clearButton.Size = new Size(82, 22);
|
clearButton.Size = new Size(94, 29);
|
||||||
clearButton.TabIndex = 2;
|
clearButton.TabIndex = 2;
|
||||||
clearButton.Text = "CLEAR";
|
clearButton.Text = "CLEAR";
|
||||||
clearButton.UseVisualStyleBackColor = true;
|
clearButton.UseVisualStyleBackColor = true;
|
||||||
@ -59,31 +61,72 @@
|
|||||||
// listBox
|
// listBox
|
||||||
//
|
//
|
||||||
listBox.Location = new Point(-3, 0);
|
listBox.Location = new Point(-3, 0);
|
||||||
listBox.Margin = new Padding(3, 2, 3, 2);
|
|
||||||
listBox.Name = "listBox";
|
listBox.Name = "listBox";
|
||||||
listBox.Size = new Size(150, 120);
|
listBox.Size = new Size(171, 160);
|
||||||
listBox.TabIndex = 3;
|
listBox.TabIndex = 3;
|
||||||
listBox.Value = "";
|
listBox.Value = "";
|
||||||
//
|
//
|
||||||
// frameTextBox1
|
// frameTextBox1
|
||||||
//
|
//
|
||||||
frameTextBox1.Location = new Point(273, 14);
|
frameTextBox1.Location = new Point(312, 19);
|
||||||
frameTextBox1.Margin = new Padding(3, 2, 3, 2);
|
|
||||||
frameTextBox1.Name = "frameTextBox1";
|
frameTextBox1.Name = "frameTextBox1";
|
||||||
frameTextBox1.Size = new Size(255, 68);
|
frameTextBox1.Size = new Size(291, 91);
|
||||||
frameTextBox1.TabIndex = 4;
|
frameTextBox1.TabIndex = 4;
|
||||||
frameTextBox1.Value = null;
|
frameTextBox1.Value = null;
|
||||||
//
|
//
|
||||||
|
// frameCustomGridView1
|
||||||
|
//
|
||||||
|
frameCustomGridView1.IndexProperty = 0;
|
||||||
|
frameCustomGridView1.Location = new Point(12, 166);
|
||||||
|
frameCustomGridView1.Name = "frameCustomGridView1";
|
||||||
|
frameCustomGridView1.Size = new Size(309, 194);
|
||||||
|
frameCustomGridView1.TabIndex = 5;
|
||||||
|
//
|
||||||
|
// buttonConfigureGridView
|
||||||
|
//
|
||||||
|
buttonConfigureGridView.Location = new Point(327, 182);
|
||||||
|
buttonConfigureGridView.Name = "buttonConfigureGridView";
|
||||||
|
buttonConfigureGridView.Size = new Size(111, 29);
|
||||||
|
buttonConfigureGridView.TabIndex = 6;
|
||||||
|
buttonConfigureGridView.Text = "CONFIGURE";
|
||||||
|
buttonConfigureGridView.UseVisualStyleBackColor = true;
|
||||||
|
buttonConfigureGridView.Click += buttonConfigureGridView_Click;
|
||||||
|
//
|
||||||
|
// fillGridViewButton
|
||||||
|
//
|
||||||
|
fillGridViewButton.Location = new Point(327, 250);
|
||||||
|
fillGridViewButton.Name = "fillGridViewButton";
|
||||||
|
fillGridViewButton.Size = new Size(111, 29);
|
||||||
|
fillGridViewButton.TabIndex = 7;
|
||||||
|
fillGridViewButton.Text = "FILL";
|
||||||
|
fillGridViewButton.UseVisualStyleBackColor = true;
|
||||||
|
fillGridViewButton.Visible = false;
|
||||||
|
fillGridViewButton.Click += fillGridViewButton_Click;
|
||||||
|
//
|
||||||
|
// getSelectedRowButton
|
||||||
|
//
|
||||||
|
getSelectedRowButton.Location = new Point(327, 285);
|
||||||
|
getSelectedRowButton.Name = "getSelectedRowButton";
|
||||||
|
getSelectedRowButton.Size = new Size(111, 29);
|
||||||
|
getSelectedRowButton.TabIndex = 8;
|
||||||
|
getSelectedRowButton.Text = "GET";
|
||||||
|
getSelectedRowButton.UseVisualStyleBackColor = true;
|
||||||
|
getSelectedRowButton.Visible = false;
|
||||||
|
getSelectedRowButton.Click += getSelectedRowButton_Click;
|
||||||
|
//
|
||||||
// TestFrame
|
// TestFrame
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(700, 338);
|
ClientSize = new Size(800, 451);
|
||||||
|
Controls.Add(getSelectedRowButton);
|
||||||
|
Controls.Add(fillGridViewButton);
|
||||||
|
Controls.Add(buttonConfigureGridView);
|
||||||
|
Controls.Add(frameCustomGridView1);
|
||||||
Controls.Add(frameTextBox1);
|
Controls.Add(frameTextBox1);
|
||||||
Controls.Add(clearButton);
|
Controls.Add(clearButton);
|
||||||
Controls.Add(fillButton);
|
Controls.Add(fillButton);
|
||||||
Controls.Add(listBox);
|
Controls.Add(listBox);
|
||||||
Margin = new Padding(3, 2, 3, 2);
|
|
||||||
Name = "TestFrame";
|
Name = "TestFrame";
|
||||||
Text = "Form1";
|
Text = "Form1";
|
||||||
ResumeLayout(false);
|
ResumeLayout(false);
|
||||||
@ -94,5 +137,9 @@
|
|||||||
private Button clearButton;
|
private Button clearButton;
|
||||||
private CustomComponents.Frame listBox;
|
private CustomComponents.Frame listBox;
|
||||||
private CustomComponents.frameTextBox frameTextBox1;
|
private CustomComponents.frameTextBox frameTextBox1;
|
||||||
|
private CustomComponents.frameCustomGridView frameCustomGridView1;
|
||||||
|
private Button buttonConfigureGridView;
|
||||||
|
private Button fillGridViewButton;
|
||||||
|
private Button getSelectedRowButton;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,3 +1,6 @@
|
|||||||
|
using CustomComponents.Classes;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
namespace TestForms
|
namespace TestForms
|
||||||
{
|
{
|
||||||
public partial class TestFrame : Form
|
public partial class TestFrame : Form
|
||||||
@ -18,7 +21,41 @@ namespace TestForms
|
|||||||
listBox.PopulateList(new List<string> { "SILENT", "RIZZ", "BLSSDY", "YUEEJKE" });
|
listBox.PopulateList(new List<string> { "SILENT", "RIZZ", "BLSSDY", "YUEEJKE" });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void buttonConfigureGridView_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
frameCustomGridView1.ColumnConfiguration(5,
|
||||||
|
new List<string>() { "ID", "Login", "LoginTimes", "Town", "Creation" },
|
||||||
|
new List<int>() { 50, 50, 50, 50, 50 },
|
||||||
|
new List<bool> { true, true, true, true, true },
|
||||||
|
new List<string> { "ID", "Login", "LoginTimes", "Town", "Creation" });
|
||||||
|
buttonConfigureGridView.Visible = false;
|
||||||
|
fillGridViewButton.Visible = true;
|
||||||
|
getSelectedRowButton.Visible = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fillGridViewButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
frameCustomGridView1.AddRows(new List<Account>()
|
||||||
|
{
|
||||||
|
new Account(1,"boba","idk"),
|
||||||
|
new Account(2,"biba","idk"),
|
||||||
|
new Account(3,"buba","idk")
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void getSelectedRowButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var obj = frameCustomGridView1.GetAccount<Account>();
|
||||||
|
|
||||||
|
var properties = obj.GetType().GetProperties();
|
||||||
|
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
|
foreach(var prop in properties)
|
||||||
|
{
|
||||||
|
sb.Append($"{prop.Name}: {prop.GetValue(obj)}\n");
|
||||||
|
}
|
||||||
|
MessageBox.Show( sb.ToString() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,64 @@
|
|||||||
<root>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<!--
|
||||||
|
Microsoft ResX Schema
|
||||||
|
|
||||||
|
Version 2.0
|
||||||
|
|
||||||
|
The primary goals of this format is to allow a simple XML format
|
||||||
|
that is mostly human readable. The generation and parsing of the
|
||||||
|
various data types are done through the TypeConverter classes
|
||||||
|
associated with the data types.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
... ado.net/XML headers & schema ...
|
||||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
|
<resheader name="version">2.0</resheader>
|
||||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
|
</data>
|
||||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||||
|
<comment>This is a comment</comment>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
There are any number of "resheader" rows that contain simple
|
||||||
|
name/value pairs.
|
||||||
|
|
||||||
|
Each data row contains a name, and value. The row also contains a
|
||||||
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
|
text/value conversion through the TypeConverter architecture.
|
||||||
|
Classes that don't support this are serialized and stored with the
|
||||||
|
mimetype set.
|
||||||
|
|
||||||
|
The mimetype is used for serialized objects, and tells the
|
||||||
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
|
read any of the formats listed below.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
|
value : The object must be serialized into a byte array
|
||||||
|
: using a System.ComponentModel.TypeConverter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
-->
|
||||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
<xsd:element name="root" msdata:IsDataSet="true">
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user