从另一个表单访问datagridview

时间:2014-06-06 12:28:30

标签: c# winforms datagridview datagrid

我从第二种形式访问数据网格时遇到了问题,我调用了向此数据网格添加数据。 代码看起来像

 public partial class adding : Form
{

    public adding()
    {
        InitializeComponent();
    }

    private void _confirmadd_Click(object sender, EventArgs e)
    {
        AlbumsDataBase.Tabela.Rows.Add("1", "XX");

    }

}

我用来从

添加数据的第二种形式
 public partial class AlbumsDataBase
{
    //

    public void InitializeComponent()
    {
        System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
        System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle();
        System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle();
        System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle4 = new System.Windows.Forms.DataGridViewCellStyle();
        System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle5 = new System.Windows.Forms.DataGridViewCellStyle();
        System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle6 = new System.Windows.Forms.DataGridViewCellStyle();
        System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle7 = new System.Windows.Forms.DataGridViewCellStyle();
        System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle8 = new System.Windows.Forms.DataGridViewCellStyle();
        System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle9 = new System.Windows.Forms.DataGridViewCellStyle();
        System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle10 = new System.Windows.Forms.DataGridViewCellStyle();
        this.backgroundWorker1 = new System.ComponentModel.BackgroundWorker();
        this.Tabela = new System.Windows.Forms.DataGridView();
        this.Number = new System.Windows.Forms.DataGridViewTextBoxColumn();
        this.ID = new System.Windows.Forms.DataGridViewTextBoxColumn();
        this.AlbumName = new System.Windows.Forms.DataGridViewTextBoxColumn();
        this.Artist = new System.Windows.Forms.DataGridViewTextBoxColumn();
        this.Genre = new System.Windows.Forms.DataGridViewTextBoxColumn();
        this.ReleaseDate = new System.Windows.Forms.DataGridViewTextBoxColumn();
        this.TracksAmount = new System.Windows.Forms.DataGridViewTextBoxColumn();
        this.AlbumLocation = new System.Windows.Forms.DataGridViewTextBoxColumn();
        this.Rating = new System.Windows.Forms.DataGridViewTextBoxColumn();
        this.add = new System.Windows.Forms.Button();
        ((System.ComponentModel.ISupportInitialize)(this.Tabela)).BeginInit();
        this.SuspendLayout();

        // 


    }

这是我对整个Datagridview的初始化。

我得到的错误:

An object reference is required for the non-static field, method, or property 'WindowApplicationJiMPSemestr2Cs.AlbumsDataBase.Tabela'

最后要提问。问题出在哪儿?是属性问题还是某些方法问题?谁能帮助我? 提前致谢

是的我知道我在“Rows.Add”中只使用了2个参数

0 个答案:

没有答案