Learn_change_myself
以有崖求无崖
2018-10-20 04:22
采纳率: 85.7%
浏览 464

窗体界面初始化中居然会报索引越界异常,灵异事件?

在初始化DataGridView控件列的HeaderText属性时报这个错,给什么值都越界,哪怕给个空格都越界,这怎么解决,江湖救急啊。我是不是遇上灵异事件了?图片说明
如下,在vs中编辑状态下能显示出来,到了运行就出现这个错误,我觉得我遇到的问题是天下独一份了,全网都没有找到答案。
图片说明

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • caozhy
    已采纳

    应该是你环境的问题,我这里测试是好的

    图片说明

    你留下邮箱,我把我这里的程序给你,你对照下。

    点赞 评论
  • Learn_change_myself
    以有崖求无崖 2018-10-20 04:42

    public partial class FrmEditMeal : Form
    {
    private DataTable TreeDt;
    private DataTable TreeChooseDt;
    private DataTable GridDt;
    private bool isLoad = true;
    public FrmEditMeal()
    {
    InitializeComponent();
    }

                private void treeView1_AfterCheck(object sender, TreeViewEventArgs e)
        {
    
        }
    
    
        private void FrmEditMeal_Load(object sender, EventArgs e)
        {
    
        }
    
        private void btnAdd_Click(object sender, EventArgs e)
        {
    
        }
    
        private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
    
        }
        }
    
    
        namespace HisDataControlLib
    

    {
    partial class FrmEditMeal
    {
    ///
    /// Required designer variable.
    ///
    private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }
    
        #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.label1 = new System.Windows.Forms.Label();
            this.tMealName = new System.Windows.Forms.TextBox();
            this.btnSearch = new System.Windows.Forms.Button();
            this.dataGridView1 = new System.Windows.Forms.DataGridView();
            this.treeView1 = new System.Windows.Forms.TreeView();
            this.btnAdd = new System.Windows.Forms.Button();
            this.btnDelete = new System.Windows.Forms.Button();
            this.TERPLATE_SETMEAL_ID = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.TERPLATE_SETMEAL_NAME = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.CREATE_DEPT_ID = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.CREATE_STAFF_ID = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.CREATE_DATE_TIME = new System.Windows.Forms.DataGridViewTextBoxColumn();
            ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
            this.SuspendLayout();
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(12, 9);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(53, 12);
            this.label1.TabIndex = 0;
            this.label1.Text = "套餐名称";
            // 
            // tMealName
            // 
            this.tMealName.Location = new System.Drawing.Point(71, 4);
            this.tMealName.Name = "tMealName";
            this.tMealName.Size = new System.Drawing.Size(100, 21);
            this.tMealName.TabIndex = 1;
            // 
            // btnSearch
            // 
            this.btnSearch.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
            this.btnSearch.Location = new System.Drawing.Point(223, 4);
            this.btnSearch.Name = "btnSearch";
            this.btnSearch.Size = new System.Drawing.Size(75, 23);
            this.btnSearch.TabIndex = 2;
            this.btnSearch.Text = "查询";
            this.btnSearch.UseVisualStyleBackColor = true;
            // 
            // dataGridView1
            // 
            this.dataGridView1.AllowUserToAddRows = false;
            this.dataGridView1.AllowUserToDeleteRows = false;
            this.dataGridView1.AllowUserToResizeRows = false;
            this.dataGridView1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                        | System.Windows.Forms.AnchorStyles.Left)));
            this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
            this.TERPLATE_SETMEAL_ID,
            this.TERPLATE_SETMEAL_NAME,
            this.CREATE_DEPT_ID,
            this.CREATE_STAFF_ID,
            this.CREATE_DATE_TIME});
            this.dataGridView1.Location = new System.Drawing.Point(2, 31);
            this.dataGridView1.MultiSelect = false;
            this.dataGridView1.Name = "dataGridView1";
            this.dataGridView1.RowHeadersVisible = false;
            this.dataGridView1.RowTemplate.Height = 23;
            this.dataGridView1.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
            this.dataGridView1.Size = new System.Drawing.Size(212, 408);
            this.dataGridView1.TabIndex = 3;
            this.dataGridView1.CellValueChanged += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellValueChanged);
            // 
            // treeView1
            // 
            this.treeView1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                        | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.treeView1.CheckBoxes = true;
            this.treeView1.Location = new System.Drawing.Point(220, 31);
            this.treeView1.Name = "treeView1";
            this.treeView1.Size = new System.Drawing.Size(243, 408);
            this.treeView1.TabIndex = 0;
            this.treeView1.AfterCheck += new System.Windows.Forms.TreeViewEventHandler(this.treeView1_AfterCheck);
            // 
            // btnAdd
            // 
            this.btnAdd.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
            this.btnAdd.Location = new System.Drawing.Point(305, 4);
            this.btnAdd.Name = "btnAdd";
            this.btnAdd.Size = new System.Drawing.Size(75, 23);
            this.btnAdd.TabIndex = 5;
            this.btnAdd.Text = "新增";
            this.btnAdd.UseVisualStyleBackColor = true;
            this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click);
            // 
            // btnDelete
            // 
            this.btnDelete.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
            this.btnDelete.Location = new System.Drawing.Point(387, 4);
            this.btnDelete.Name = "btnDelete";
            this.btnDelete.Size = new System.Drawing.Size(75, 23);
            this.btnDelete.TabIndex = 6;
            this.btnDelete.Text = "删除";
            this.btnDelete.UseVisualStyleBackColor = true;
            // 
            // TERPLATE_SETMEAL_ID
            // 
            this.TERPLATE_SETMEAL_ID.DataPropertyName = "TERPLATE_SETMEAL_ID";
            this.TERPLATE_SETMEAL_ID.HeaderText = "套餐编号";
            this.TERPLATE_SETMEAL_ID.Name = "TERPLATE_SETMEAL_ID";
            this.TERPLATE_SETMEAL_ID.Visible = false;
            // 
            // TERPLATE_SETMEAL_NAME
            // 
            this.TERPLATE_SETMEAL_NAME.DataPropertyName = "TERPLATE_SETMEAL_NAME";
            this.TERPLATE_SETMEAL_NAME.HeaderText = "套餐名称";
            this.TERPLATE_SETMEAL_NAME.Name = "TERPLATE_SETMEAL_NAME";
            // 
            // CREATE_DEPT_ID
            // 
            this.CREATE_DEPT_ID.DataPropertyName = "CREATE_DEPT_ID";
            this.CREATE_DEPT_ID.HeaderText = "创建科室编号";
            this.CREATE_DEPT_ID.Name = "CREATE_DEPT_ID";
            this.CREATE_DEPT_ID.Visible = false;
            // 
            // CREATE_STAFF_ID
            // 
            this.CREATE_STAFF_ID.DataPropertyName = "CREATE_STAFF_ID";
            this.CREATE_STAFF_ID.HeaderText = "创建人编号";
            this.CREATE_STAFF_ID.Name = "CREATE_STAFF_ID";
            this.CREATE_STAFF_ID.Visible = false;
            // 
            // CREATE_DATE_TIME
            // 
            this.CREATE_DATE_TIME.DataPropertyName = "CREATE_DATE_TIME";
            this.CREATE_DATE_TIME.HeaderText = "创建时间";
            this.CREATE_DATE_TIME.Name = "CREATE_DATE_TIME";
            this.CREATE_DATE_TIME.ReadOnly = true;
            // 
            // FrmEditMeal
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(466, 442);
            this.Controls.Add(this.dataGridView1);
            this.Controls.Add(this.btnDelete);
            this.Controls.Add(this.btnAdd);
            this.Controls.Add(this.treeView1);
            this.Controls.Add(this.btnSearch);
            this.Controls.Add(this.tMealName);
            this.Controls.Add(this.label1);
            this.Name = "FrmEditMeal";
            this.Text = "套餐维护";
            this.Load += new System.EventHandler(this.FrmEditMeal_Load);
            ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();
    
        }
    
        #endregion
    
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.TextBox tMealName;
        private System.Windows.Forms.Button btnSearch;
        private System.Windows.Forms.DataGridView dataGridView1;
        private System.Windows.Forms.TreeView treeView1;
        private System.Windows.Forms.Button btnAdd;
        private System.Windows.Forms.Button btnDelete;
        private System.Windows.Forms.DataGridViewTextBoxColumn TERPLATE_SETMEAL_ID;
        private System.Windows.Forms.DataGridViewTextBoxColumn TERPLATE_SETMEAL_NAME;
        private System.Windows.Forms.DataGridViewTextBoxColumn CREATE_DEPT_ID;
        private System.Windows.Forms.DataGridViewTextBoxColumn CREATE_STAFF_ID;
        private System.Windows.Forms.DataGridViewTextBoxColumn CREATE_DATE_TIME;
    }
    

    }

    点赞 评论

相关推荐