Avatar of Rama Tito
Rama Tito
Flag for Malaysia asked on

Creating a DataGridView by coding


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()

        /// <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();
            // 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";

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main()


Open in new window


Avatar of undefined
Last Comment
Bob Learned

8/22/2022 - Mon
Bob Learned

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Your help has saved me hundreds of hours of internet surfing.