diff --git a/CustomComponents/Classes/Account.cs b/CustomComponents/Classes/Account.cs index 950c63e..3e201d1 100644 --- a/CustomComponents/Classes/Account.cs +++ b/CustomComponents/Classes/Account.cs @@ -14,6 +14,10 @@ namespace CustomComponents.Classes public string Town { get; private set; } = string.Empty; public DateTime CreationDate { get; private set; } = DateTime.Now; + public Account() + { + + } public Account(int id, string login, string town) { ID = id; diff --git a/CustomComponents/CustomDataGridView.cs b/CustomComponents/CustomDataGridView.cs index ee07e39..ff562c0 100644 --- a/CustomComponents/CustomDataGridView.cs +++ b/CustomComponents/CustomDataGridView.cs @@ -54,7 +54,7 @@ namespace CustomComponents customGridView.Rows.Clear(); } - public void AddRow(List objects) + public void AddRows(List objects) { var type = objects.GetType(); var fields = type.GetProperties(); @@ -63,7 +63,16 @@ namespace CustomComponents { List values = new(); 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); } } diff --git a/TestForms/Form1.Designer.cs b/TestForms/Form1.Designer.cs index 533ab72..cb7c1ac 100644 --- a/TestForms/Form1.Designer.cs +++ b/TestForms/Form1.Designer.cs @@ -32,14 +32,17 @@ clearButton = new Button(); listBox = new CustomComponents.Frame(); frameTextBox1 = new CustomComponents.frameTextBox(); + frameCustomGridView1 = new CustomComponents.frameCustomGridView(); + buttonConfigureGridView = new Button(); + fillGridViewButton = new Button(); + getSelectedRowButton = new Button(); SuspendLayout(); // // fillButton // - fillButton.Location = new Point(153, 14); - fillButton.Margin = new Padding(3, 2, 3, 2); + fillButton.Location = new Point(175, 19); fillButton.Name = "fillButton"; - fillButton.Size = new Size(82, 22); + fillButton.Size = new Size(94, 29); fillButton.TabIndex = 1; fillButton.Text = "FILL"; fillButton.UseVisualStyleBackColor = true; @@ -47,10 +50,9 @@ // // clearButton // - clearButton.Location = new Point(153, 56); - clearButton.Margin = new Padding(3, 2, 3, 2); + clearButton.Location = new Point(175, 75); clearButton.Name = "clearButton"; - clearButton.Size = new Size(82, 22); + clearButton.Size = new Size(94, 29); clearButton.TabIndex = 2; clearButton.Text = "CLEAR"; clearButton.UseVisualStyleBackColor = true; @@ -59,31 +61,72 @@ // listBox // listBox.Location = new Point(-3, 0); - listBox.Margin = new Padding(3, 2, 3, 2); listBox.Name = "listBox"; - listBox.Size = new Size(150, 120); + listBox.Size = new Size(171, 160); listBox.TabIndex = 3; listBox.Value = ""; // // frameTextBox1 // - frameTextBox1.Location = new Point(273, 14); - frameTextBox1.Margin = new Padding(3, 2, 3, 2); + frameTextBox1.Location = new Point(312, 19); frameTextBox1.Name = "frameTextBox1"; - frameTextBox1.Size = new Size(255, 68); + frameTextBox1.Size = new Size(291, 91); frameTextBox1.TabIndex = 4; 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 // - AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleDimensions = new SizeF(8F, 20F); 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(clearButton); Controls.Add(fillButton); Controls.Add(listBox); - Margin = new Padding(3, 2, 3, 2); Name = "TestFrame"; Text = "Form1"; ResumeLayout(false); @@ -94,5 +137,9 @@ private Button clearButton; private CustomComponents.Frame listBox; private CustomComponents.frameTextBox frameTextBox1; + private CustomComponents.frameCustomGridView frameCustomGridView1; + private Button buttonConfigureGridView; + private Button fillGridViewButton; + private Button getSelectedRowButton; } } \ No newline at end of file diff --git a/TestForms/Form1.cs b/TestForms/Form1.cs index 35de418..24768d9 100644 --- a/TestForms/Form1.cs +++ b/TestForms/Form1.cs @@ -1,3 +1,6 @@ +using CustomComponents.Classes; +using System.Text; + namespace TestForms { public partial class TestFrame : Form @@ -18,7 +21,41 @@ namespace TestForms listBox.PopulateList(new List { "SILENT", "RIZZ", "BLSSDY", "YUEEJKE" }); } + private void buttonConfigureGridView_Click(object sender, EventArgs e) + { + frameCustomGridView1.ColumnConfiguration(5, + new List() { "ID", "Login", "LoginTimes", "Town", "Creation" }, + new List() { 50, 50, 50, 50, 50 }, + new List { true, true, true, true, true }, + new List { "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() + { + 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(); + + 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() ); + } } } \ No newline at end of file diff --git a/TestForms/Form1.resx b/TestForms/Form1.resx index f298a7b..af32865 100644 --- a/TestForms/Form1.resx +++ b/TestForms/Form1.resx @@ -1,4 +1,64 @@ - + + +