Hello,
I downloaded the datagridview summary and added to my sample project,
Here is my model class
public class SimpleModel
{
public Guid ID { get; set; }
public string DESCRIPTION { get; set; }
public decimal? AMOUNT { get; set; }
}
Here is my code to populate a simple list
list.Add(new SimpleModel() {
ID=Guid.NewGuid(),
DESCRIPTION=”Sample #1″,
AMOUNT=500
});
list.Add(new SimpleModel()
{
ID = Guid.NewGuid(),
DESCRIPTION = “Sample #2”,
AMOUNT = 600
});
list.Add(new SimpleModel()
{
ID = Guid.NewGuid(),
DESCRIPTION = “Sample #3”,
AMOUNT = 700
});
dataGridView1.DataSource = list;
dataGridView1.AddSummaryRows(SummaryType.Sum, SummaryRowPosition.Below, colAMOUNT, colAMOUNT); —error here????
This is the error message : System.InvalidOperationException: ‘Rows cannot be programmatically added to the DataGridView’s rows collection when the control is data-bound.’
Thanks.
That’s the correct error. If the data grid is data bound then adding summary rows adds them to the data source, which is incorrect.
You can add rows programmatically or you can try the datagrid1.Fill() methods to load the data source without being data bound.