【问题标题】:the type of namespace of rows could not be found找不到行的命名空间类型
【发布时间】:2015-02-15 06:23:48
【问题描述】:

我得到如下错误:

找不到行的命名空间类型

这是我的代码:

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;
    }
}

【问题讨论】:

    标签: c# vb.net visual-studio-2012 datagridview


    【解决方案1】:

    您的命名空间 DataGridView1 在这里造成了歧义。您的控件的 ID“dataGridView1”是否带有小写“d”?

    【讨论】:

    • 是的,应该是"dataGridView.Rows.Add("1", "Mei", "Penang", "Edit", "Delete");",但是我不能添加时我调试
    • 在您发布的代码(方法“dataGridView1_CellContentClick”)中,您有“DataGridView1”和大写的“D”,对应于命名空间。
    • 我改了上面的代码,还是不能添加到行中,这是怎么回事?我是第一次使用这个
    • 你的DataGridView的ID是什么?你能把你表单的designer.cs代码的代码贴出来吗?
    • 您的事件处理程序接线似乎错误。您正在连接到“dataGridView1_CellContentClick”,但 from 中的方法仍然有“DataGridView1_CellContentClick”和大写“D”。除此之外,我认为没有任何其他问题。更改此设置后,如果您遇到任何编译时或运行时错误,请告诉我。
    【解决方案2】:

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

    请记住,仅添加命名空间并不总能解决您的错误。

    【讨论】:

    • @user4562396 如果您已经创建了行,请确保它位于命名空间内并确保将其包含在您的示例代码中。
    猜你喜欢
    • 1970-01-01
    • 2013-03-25
    • 1970-01-01
    • 1970-01-01
    • 2017-07-12
    • 2011-05-13
    • 2021-03-01
    • 2020-08-13
    相关资源
    最近更新 更多