Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/268.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 找不到行的命名空间类型_C#_Vb.net_Visual Studio 2012_Datagridview - Fatal编程技术网

C# 找不到行的命名空间类型

C# 找不到行的命名空间类型,c#,vb.net,visual-studio-2012,datagridview,C#,Vb.net,Visual Studio 2012,Datagridview,我得到的错误如下: 找不到行的命名空间类型 这是我的密码: using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Data; name

我得到的错误如下:

找不到行的命名空间类型

这是我的密码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data;


namespace DataGridView1
{
    public partial class Cust_Form : Form
    {
        public Cust_Form()
        {
            InitializeComponent();
        }


        private void DataGridView1_Load(object sender, DataGridViewCellEventArgs e)
        {

            dataGridView.Rows.Add("1", "Mei", "US");
            dataGridView.Rows.Add("2", "Wei", "US");
        }

        //private void Cust_Form_Load(object sender, EventArgs e)
        //{

        //}
    }
}
我应该添加什么名称空间来消除此错误?我在行中得到了我的错误

Cust_Form.Designer.cs

namespace DataGridView1
{
    partial class Cust_Form
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        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.SuspendLayout();
            // 
            // Cust_Form
            // 
            this.ClientSize = new System.Drawing.Size(284, 261);
            this.Name = "Cust_Form";
            this.Load += new System.EventHandler(this.Cust_Form_Load);
            this.ResumeLayout(false);

        }

        #endregion

        private System.Windows.Forms.DataGridView dataGridView;
        private System.Windows.Forms.DataGridViewTextBoxColumn Column1;
        private System.Windows.Forms.DataGridViewTextBoxColumn Column2;
        private System.Windows.Forms.DataGridViewTextBoxColumn Column3;
        private System.Windows.Forms.DataGridViewButtonColumn Column5;
        private System.Windows.Forms.DataGridViewButtonColumn Column4;
    }
}

您的名称空间DataGridView1在这里造成了歧义。控件的ID dataGridView1是否小写为d?

您正在尝试访问dataGridView1.Rows,但在命名空间dataGridView1中似乎没有Rows类的声明。 确保存在这样的实现


记住,仅仅添加一个名称空间并不总是能够修复您的错误。

@user4562396如果您创建了行,请确保它位于名称空间内,并确保将其包含在示例代码中。是的,它应该是dataGridView.Rows.Add1、Mei、Penang、Edit、Delete;,但是我在调试您发布的代码方法dataGridView1_CellContentClick时无法添加它,您的dataGridView1的大写字母为D,对应于名称空间。我已按上述方式更改了代码,但它仍然无法添加到行中,这有什么问题?我是第一次使用它你的DataGridView的ID是什么?您可以发布表单的designer.cs代码吗?您的事件处理程序连接似乎错误。您正在连接到dataGridView1\u CellContentClick,但是from中的方法仍然具有带大写字母D的dataGridView1\u CellContentClick。除此之外,我认为没有任何其他问题。更改此选项后,如果您遇到任何编译时或运行时错误,请告诉我。