Creating a DataGridView by coding

Rama Tito
Rama Tito used Ask the Experts™
on
Hi,

I am trying to create a empty datagridview by coding. When i am trying to execute, no error and no form. Its just switch from program mode to run mode and back to program mode by itself.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace GridSetting
{
    public partial class MainGrid : System.Windows.Forms.Form
    {
        private System.Windows.Forms.DataGridView dataGridViewBase;
        private System.Windows.Forms.DataGridViewTextBoxColumn dataGridTextBoxColumn2;
        private System.Windows.Forms.DataGridViewTextBoxColumn dataGridTextBoxColumn3;
        private System.Windows.Forms.DataGridViewTextBoxColumn dataGridTextBoxColumn4;
        private System.Windows.Forms.DataGridViewTextBoxColumn dataGridTextBoxColumn5;

        public MainGrid()
        {
            InitializeComponent();
        }

        /// <summary>
		/// Clean up any resources being used.
		/// </summary>
		

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
        private void InitializeComponent()
        {
            this.dataGridViewBase = new System.Windows.Forms.DataGridView();
            this.dataGridTextBoxColumn2 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.dataGridTextBoxColumn3 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.dataGridTextBoxColumn4 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.dataGridTextBoxColumn5 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            ((System.ComponentModel.ISupportInitialize)(this.dataGridViewBase)).BeginInit();
            
            // 
            // dataGridViewBase
            // 
            this.dataGridViewBase.Location = new System.Drawing.Point(0, 0);
            this.dataGridViewBase.Name = "dataGridViewBase";
            this.dataGridViewBase.Size = new System.Drawing.Size(240, 150);
            this.dataGridViewBase.TabIndex = 0;
            
            // 
            // dataGridTextBoxColumn2
            // 
            this.dataGridTextBoxColumn2.Name = "dataGridTextBoxColumn2";
            // 
            // dataGridTextBoxColumn3
            // 
            this.dataGridTextBoxColumn3.Name = "dataGridTextBoxColumn3";
            // 
            // dataGridTextBoxColumn4
            // 
            this.dataGridTextBoxColumn4.Name = "dataGridTextBoxColumn4";
            // 
            // dataGridTextBoxColumn5
            // 
            this.dataGridTextBoxColumn5.Name = "dataGridTextBoxColumn5";
            // 
            // MainGrid
            // 
            this.ClientSize = new System.Drawing.Size(292, 266);
            this.Name = "MainGrid";
            ((System.ComponentModel.ISupportInitialize)(this.dataGridViewBase)).EndInit();
            this.ResumeLayout(false);

        }
        #endregion
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.DoEvents();
            
        }





    }
}

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2012
Top Expert 2008
Commented:
static void Main()
        {
            Application.EnableVisualStyles();
            Application.DoEvents();
            Application.Run(new MainGrid());          
        }

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial