1

我在 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");

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

感谢您的任何建议...

4

0 回答 0