DataGridViewRow r = dataGridView1.NewRow();

解决方案 »

  1.   

     int t = this.dataGridView1.Rows.Add();
      this.dataGridView1.Rows[t].Cells["cols1"].Value="aaaaa"; 
      

  2.   

    DataGridViewRow dgr = new DataGridViewRow();
                           dgr.CreateCells(dgvQuatoSetting);//dgvQuatoSetting为grdiview控件的name
                           
                            
                            dgr.Cells[0].Value=leftName;
                            dgr.Cells[1].Value = rightName;
      

  3.   

    搂主的问题原因是:
    下面创建行的这句代码:
    DataGridViewRow r = new DataGridViewRow(); 
    这个时候,仅仅是创建了一个DataGridViewRow 对象,但是还没有添加到DataGridView里面去
    所以这个时候r还是没有任何列的,然后如果设置它的单元格值:
    r.Cells["cols1"].Value="aaaaa"; 
    r.Cells["cols2"].Value="bbbbb"; 
    就会出异常了。搂主应该这样做:
    int index = dataGridView1.Rows.Add(); 
    DataGridViewRow row = dataGridView1.Rows[index];
    row.Cells["cols1"].Value="aaaaa"; 
    row.Cells["cols2"].Value="bbbbb"; 

    这样就没问题了。后面两句,搂主这样写效率会更高些:
    row.Cells[0].Value="aaaaa"; 
    row.Cells[1].Value="bbbbb"; 
      

  4.   


    dataGridViewSelectedAddress.Rows.Add("aaaaa","bbbbb");//有4种参数,这应该第一种吧~这样写就不用考虑列名了,当然你必须保证前两列是对应好的~
      

  5.   

    求助,vc++做像QQ宠物那样,透明不规则flash demo程序
    谢谢了
      

  6.   

    因为你没有指定DataGridViewRow的列集合
    方法一:DataRow myRow=dataGridView1.rows[i];row.Cells["cols1"].Value="aaaaa"; 
    row.Cells["cols2"].Value="bbbbb"; 
    方法一:
    也可以现在数据集中添加然后绑定到dataGridView1中,这样功能更强大
    DataTable myTable=dataSet.Tables[0];
    DataRow myRow=myTable.NewRow();
    myRow.Cells["cols1"].Value="aaaaa"; 
    myRow.Cells["cols2"].Value="bbbbb";