C#DataGridView.Rows.Add问题

时间:2013-07-28 08:48:43

标签: c# datagridview windows-forms-designer

我在C#上有DataGridView的问题

我有类似这样的课程定义

class cls{
   bool is_checked;
   string id;
   string name;
   string description;

   constructor,getters,setters...etc
}

这是我的Form1.Designer.cs

this.datagridview = new System.Windows.Forms.DataGridView();
this.datagridview_checkbox_column = new System.Windows.Forms.DataGridViewCheckBoxColumn();


this.datagridview .ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.datagridview .Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.datagridview_checkbox_column});
this.datagridview .Name = "datagridview";
this.datagridview .AllowUserToAddRows = false;
this.datagridview .Size = new System.Drawing.Size(565, 315);
this.datagridview .ColumnCount = 4;
this.datagridview .Columns[1].Name = "ID";
this.datagridview .Columns[2].Name = "Name";
this.datagridview .Columns[3].Name = "Description";


this.datagridview_checkbox_column.HeaderText = "";
this.datagridview_checkbox_column.Name = "datagridview_checkbox_column";

private System.Windows.Forms.DataGridView datagridview;
    private System.Windows.Forms.DataGridViewCheckBoxColumn datagridview_checkbox_column;

我的Form1.cs

public Form1()
    {
        InitializeComponent();
        initalize();
    }

    private void initalize() {
        Cls cls1=new cls(true,"string1","string2","string3");
        datagridview.Rows.Add(cls1.getIsChecked(), cls1.getId(), cls1.getName(), cls1.getDescription());
    }

我的问题是:

datagridview.Rows.Add(cls1.getIsChecked(), cls1.getId(), cls1.getName(), cls1.getDescription());

我收到此错误:

  

DataGridViewRowCollection.Add(params object [])的最佳重载方法匹配有一些无效的参数

但是当我这样输入时:

datagridview.Rows.Add(true,"sss","sss","sss");

我没有得到任何编译错误。为什么?你能帮帮我吗

感谢您的任何建议......

0 个答案:

没有答案