We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Add new row (end table)

And another question) How to add a row but in the end, but not to the top of the all inserted

3 Replies

MG Mohanraj Gunasekaran Syncfusion Team February 21, 2017 05:52 AM UTC

Hi Slava,  
  
Thanks for using Syncfusion products.  
  
In order to add the new row at end of the table in GridControl, you can use the GridControl.Rows.InsertRange method. Please make use of the below code and refer the below attached sample  
  
Code Example  
private void addRowsBtn_Click(object sender, EventArgs e)  
{  
    this.gridControl1.Rows.InsertRange(this.gridControl1.RowCount + 1, 1);  
}  
  
  
Sample link: GridControl  
 
Regards,  
Mohanraj G


SL Slava replied to Mohanraj Gunasekaran February 21, 2017 07:48 AM UTC

Hi Slava,  
  
Thanks for using Syncfusion products.  
  
In order to add the new row at end of the table in GridControl, you can use the GridControl.Rows.InsertRange method. Please make use of the below code and refer the below attached sample  
  
Code Example  
private void addRowsBtn_Click(object sender, EventArgs e)  
{  
    this.gridControl1.Rows.InsertRange(this.gridControl1.RowCount + 1, 1);  
}  
  
  
Sample link: GridControl  
 
Regards,  
Mohanraj G

Thanks for the answer. But now the problem with filling column
I was here such code:
                    this.checkGrid.Rows.InsertRange(1, 1);
                   
this.checkGrid[1, 1].Text = item.Attribute("text").Value;
                   
this.checkGrid[1, 2].CellValue = item.Attribute("kol").Value;
                   
this.checkGrid[1, 3].Text = item.Attribute("ed").Value;
                   
this.checkGrid[1, 4].CellValue = item.Attribute("cost").Value;
                   
this.checkGrid[1, 5].CellValue = item.Attribute("skidka").Value;
                   
this.checkGrid[1, 6].CellType = GridCellTypeName.FormulaCell;
                   
this.checkGrid[1, 6].CellValue = "=" + "(" + item.Attribute("kol").Value + "*" + item.Attribute("cost").Value + ")" + "*" + "(" + "1" + "-" + item.Attribute("skidka").Value + ")";
                   
this.checkGrid.Refresh();

I changed your decision

                    this.checkGrid.Rows.InsertRange(this.checkGrid.RowCount +1, 1);
                   
this.checkGrid[this.checkGrid.RowCount +1, 1].Text = item.Attribute("text").Value;
                   
this.checkGrid[this.checkGrid.RowCount +1, 2].CellValue = item.Attribute("kol").Value;
                   
this.checkGrid[this.checkGrid.RowCount +1, 3].Text = item.Attribute("ed").Value;
                   
this.checkGrid[this.checkGrid.RowCount +1, 4].CellValue = item.Attribute("cost").Value;
                   
this.checkGrid[this.checkGrid.RowCount +1, 5].CellValue = item.Attribute("skidka").Value;
                   
this.checkGrid[this.checkGrid.RowCount +1, 6].CellType = GridCellTypeName.FormulaCell;
                   
this.checkGrid[this.checkGrid.RowCount +1, 6].CellValue = "=" + "(" + item.Attribute("kol").Value + "*" + item.Attribute("cost").Value + ")" + "*" + "(" + "1" + "-" + item.Attribute("skidka").Value + ")";
                   
this.checkGrid.Refresh();


Lines are added but empty. Without filling (


MG Mohanraj Gunasekaran Syncfusion Team February 22, 2017 12:49 PM UTC

Hi Slava,     
   
Thanks for your update.   
   
We have analyzed your provided code part. If you have used the InsertRange method to add the new row for GridControl, then row count will be increased automatically. So please use the “RowCount” instead of “RowCount + 1” to set the value for new row. Please refer the below code example and attached sample,   
   
Code example   
//Row count is 25   
 this.checkGrid.Rows.InsertRange(this.checkGrid.RowCount +1, 1); //Now row count is 2  
this.checkGrid[this.checkGrid.RowCount +1, 1].Text = item.Attribute("text").Value; //So you have tried to set the value for 27th row. But there is not presenting the 27th row in GridCotnrol   
   
Please modify your code like below   
this.checkGrid[this.checkGrid.RowCount , 1].Text = item.Attribute("text").Value;   
this.checkGrid[this.checkGrid.RowCount, 2].CellValue = item.Attribute("kol").Value;
this.checkGrid[this.checkGrid.RowCount, 3].Text = item.Attribute("ed").Value;
this.checkGrid[this.checkGrid.RowCount, 4].CellValue = item.Attribute("cost").Value;
this.checkGrid[this.checkGrid.RowCount, 5].CellValue = item.Attribute("skidka").Value;
this.checkGrid[this.checkGrid.RowCount, 6].CellType = GridCellTypeName.FormulaCell; this.checkGrid[this.checkGrid.RowCount +1, 6].CellValue = "=" + "(" + item.Attribute("kol").Value + "*" + item.Attribute("cost").Value + ")" + "*" + "(" + "1" + "-" + item.Attribute("skidka").Value + ")";
   
   
Sample link: GridControl   
   
Regards,   
Mohanraj G   
 


Loader.
Up arrow icon