title: General style for multiple dataGridView applications (General settings)
body: <p>The app has multiple dataGridViews.<br />
  <strong>Example.</strong><br />
  There is: dataGridView-3 pieces(dataGridView1, dataGridView2, dataGridView3).<br />
  How to do:</p>
  <ul>
  <li>dataGridView1-2 - has settings-1;</li>
  <li>dataGridView3 - has settings-2.</li>
  </ul>
  <p>In other words, I set which &quot;dataGridView&quot; uses which settings.</p>
  <p><strong>Question.</strong><br />
  How to make a common style for multiple dataGridView applications?</p>
  <p>I created a solution.
  <strong>Result:</strong> I get an empty UserControl</p>
  <p><strong>Picture-1</strong><br />
  <a href="https://i.stack.imgur.com/euwD9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/euwD9.png" alt="enter image description here" /></a></p>
  <p>Code <strong>MyGrid</strong></p>
  <pre><code>class MyGrid: DataGridView
      {
          public MyGrid ()
          {
               // this = new System.Windows.Forms.DataGridView ();
              // ((System.ComponentModel.ISupportInitialize) (this)). BeginInit ();
              //this.SuspendLayout ();
              //
              // dgw
              //
              this.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
              // this.dgv.Location = new System.Drawing.Point (20, 64);
              this.Name = &quot;dgw&quot;;
              this.Size = new System.Drawing.Size (419, 173);
              // this.dgv.TabIndex = 0;
   
   
   
   
              // this.Columns [&quot;Name&quot;]. Width = 70; // Change the width. Field - &quot;Name&quot;
              // this.Columns [&quot;Property&quot;]. Width = 70; // Change the width. Field - &quot;Property&quot;
              // this.Columns [0] .Width = 70; // Change the width. Field - &quot;Name&quot;
              // this.Columns [1] .Width = 70; // Change the width. Field - &quot;Property&quot;
   
              this.RowHeadersWidth = 20; // Width &quot;Title of rows&quot;
              this.AllowUserToAddRows = false; // `false` - disable the line for adding a&quot; new record &quot;
              this.ReadOnly = true; // Editing
   
              this.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; // Auto-fit width.
   
              this.SelectionMode = DataGridViewSelectionMode.FullRowSelect; // Select the entire line
              this.MultiSelect = false; // Multi-select
              this.Columns.Cast &lt;DataGridViewColumn&gt; () .ToList (). ForEach (f =&gt; f.SortMode = DataGridViewColumnSortMode.NotSortable); // Disable sorting
   
              // this.Size.Width = 400;
              // this.Size.Height = 170;
              
          }
   
      }
  </code></pre>
  <p>Code <strong>UserControl1</strong></p>
  <pre><code>public partial class UserControl1 : UserControl
      {
          public UserControl1()
          {
              InitializeComponent();
   
              DataTable dt = new DataTable();
              
              dt.Columns.Add(&quot;Name&quot;, typeof(string));
              dt.Columns.Add(&quot;Property&quot;, typeof(string));            
   
              dt.Rows.Add(&quot;Name_1&quot;, &quot;Property_1&quot;);
              dt.Rows.Add(&quot;Name_2&quot;, &quot;Property_2&quot;);
              dt.Rows.Add(&quot;Name_3&quot;, &quot;Property_3&quot;);
                   
              //
              MyGrid myGrid = new MyGrid();                
              myGrid.Location = new Point(20, 64);
              myGrid.TabIndex = 0;
   
              myGrid.DataSource = dt;
          }
      }
  </code></pre>
  <p>Code <strong>MainForm</strong></p>
  <pre><code>namespace WinForm
  {
      public partial class MainForm : Form
      {
          public MainForm()
          {
              InitializeComponent();
          }
   
          private void button1_Click(object sender, EventArgs e)
          {
              var userControl1 = new UserControl1();
              panel1.Controls.Clear();            
              panel1.Controls.Add(userControl1);           
   
          }
   
          private void button2_Click(object sender, EventArgs e)
          {
              var userControl2 = new UserControl2();
              panel1.Controls.Clear();
              panel1.Controls.Add(userControl2);
          }
      }
  }
  </code></pre>