I am developing a windows form accounting application. The application generates accounting ledger of the entries. User selects a date period between which ledger has been generated. The opening balance is calculated logically after getting values from database. The problem is, how to display opening and closing balance on first and last row of datagridview respectively because the rows of datagridview are databound.
Code:
dataGridView1.AutoGenerateColumns = false;
dt = new DataTable();
sda = new SqlDataAdapter("select CONVERT(varchar,date,101) as date,desc,credit,debit where user_Id='" + comboBox1.SelectedValue + "' and date BETWEEN'" + dateTimePicker1.Value.Date + "'AND'" + dateTimePicker2.Value.Date + "'", con);
sda.Fill(dt);
dataGridView1.ColumnCount = 3;
dataGridView1.Columns[0].Name = "date";
dataGridView1.Columns[0].HeaderText = "Date";
dataGridView1.Columns[0].DataPropertyName = "date";
dataGridView1.Columns[1].Name = "desc";
dataGridView1.Columns[1].HeaderText = "Description";
dataGridView1.Columns[1].DataPropertyName = "desc";
dataGridView1.Columns[2].Name = "credit";
dataGridView1.Columns[2].HeaderText = "Credit";
dataGridView1.Columns[2].DataPropertyName = "credit";
dataGridView1.Columns[3].Name = "debit";
dataGridView1.Columns[3].HeaderText = "Debit";
dataGridView1.Columns[3].DataPropertyName = "debit";
Now, when i calculate opening balance and add it directly using datagridview1.Rows.Add(), then it gives error saying that you can't add row programmatically because the rows are databounded.
So, please help me in my implementation. If you have some other for showing balance then please mention.