Last active
January 9, 2019 10:46
-
-
Save Konctantin/9288aaf26cce74e84eaef0de0bc162f7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Data; | |
| using System.Drawing; | |
| using System.Windows.Forms; | |
| public class Form1 : Form | |
| { | |
| private DataTable table = new DataTable(); | |
| private MyDataGridView dataGridView1 = new MyDataGridView(); | |
| private DataGridView dataGridView2 = new DataGridView(); | |
| private BindingSource bindingSource1 = new BindingSource(); | |
| private BindingSource bindingSource2 = new BindingSource(); | |
| private SplitContainer splitContainer1 = new SplitContainer(); | |
| private Label label1 = new Label(); | |
| private Label label2 = new Label(); | |
| private void FillTable() | |
| { | |
| for (int col = 0; col < 100; ++col) | |
| table.Columns.Add("Col_" + col); | |
| var rand = new Random(); | |
| for (int row = 0; row < 1000; ++row) | |
| { | |
| var curRow = table.NewRow(); | |
| for (int col = 0; col < 100; ++col) | |
| { | |
| curRow[col] = rand.Next(1, 1000); | |
| } | |
| table.Rows.Add(curRow); | |
| } | |
| } | |
| public Form1() | |
| { | |
| FillTable(); | |
| // bindingSource | |
| bindingSource1.DataSource = table; | |
| bindingSource2.DataSource = table; | |
| // label1 | |
| label1.AutoSize = true; | |
| label1.Dock = DockStyle.Top; | |
| label1.ForeColor = Color.Blue; | |
| label1.Text = "MyDataGridView"; | |
| // label2 | |
| label2.AutoSize = true; | |
| label2.Dock = DockStyle.Top; | |
| label2.ForeColor = Color.Red; | |
| label2.Text = "DataGridView"; | |
| // splitContainer1 | |
| splitContainer1.Dock = DockStyle.Fill; | |
| splitContainer1.Panel1.Controls.Add(label1); | |
| splitContainer1.Panel2.Controls.Add(label2); | |
| splitContainer1.SplitterDistance = Width / 2; | |
| // dataGridView1 | |
| dataGridView1.DataSource = bindingSource1; | |
| dataGridView1.Dock = DockStyle.Fill; | |
| dataGridView1.AutoGenerateColumns = true; | |
| // dataGridView2 | |
| dataGridView2.DataSource = bindingSource2; | |
| dataGridView2.Dock = DockStyle.Fill; | |
| dataGridView2.AutoGenerateColumns = true; | |
| // append controls | |
| splitContainer1.Panel1.Controls.Add(dataGridView1); | |
| splitContainer1.Panel2.Controls.Add(dataGridView2); | |
| splitContainer1.Panel1.Controls.Add(label1); | |
| splitContainer1.Panel2.Controls.Add(label2); | |
| Controls.Add(splitContainer1); | |
| // resize form | |
| Resize += (o, e) => splitContainer1.SplitterDistance = Width / 2; | |
| Width = 800; | |
| Height = 500; | |
| } | |
| } | |
| public class MyDataGridView : DataGridView | |
| { | |
| public MyDataGridView() | |
| { | |
| DoubleBuffered = true; | |
| } | |
| } | |
| static class Program | |
| { | |
| [STAThread] | |
| static void Main() | |
| { | |
| Application.Run(new Form1()); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment