TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Ajit N
NA
352
72k
How to make running total in DataGridView ?
Jan 9 2019 7:30 AM
I want to make running total in datagridview. i tried some code on datagridview's sorted event but i didn't get the expected output.
My Code show's this type of data in DataGridView-
But I expect this output-
So Help me how can i solve it ?
public
void
ShowData()
{
OleDbCommand cmd =
new
OleDbCommand(
"SELECT OB as OpenBalnce,PCB as CloasingBalance,LC as lcno from Balance where LC="
+ txtticket.Text +
""
, con);
OleDbDataAdapter da =
new
OleDbDataAdapter(cmd);
DataTable dt =
new
DataTable();
da.Fill(dt);
OleDbCommand cmd2 =
new
OleDbCommand(
"SELECT amount as Debit,LC as lcno,Narra as Narration,dt as Edate FROM voucher where DrCr='Dr' and FYear='"
+ cmbyear.Text +
"' and LC="
+ txtticket.Text +
" order by dt ASC"
, con);
OleDbDataAdapter da2 =
new
OleDbDataAdapter(cmd2);
DataTable dt2 =
new
DataTable();
da2.Fill(dt2);
dt2.Merge(dt);
dt2.AcceptChanges();
OleDbCommand cmd1 =
new
OleDbCommand(
"SELECT LC as lcno,amount as Credit,Narra as Narration,dt as Edate FROM voucher where DrCr='Cr' and FYear='"
+ cmbyear.Text +
"' and LC="
+ txtticket.Text +
" order by dt ASC"
, con);
OleDbDataAdapter da1 =
new
OleDbDataAdapter(cmd1);
DataTable dt1 =
new
DataTable();
da1.Fill(dt1);
dt1.Merge(dt2);
dt1.AcceptChanges();
dataGridView1.DataSource = dt1;
dataGridView1.Sort(
this
.dataGridView1.Columns[3], ListSortDirection.Ascending);
}
private
void
dataGridView1_Sorted(
object
sender, EventArgs e)
{
for
(
int
i = 1; i < dataGridView1.Rows.Count - 1; i++)
{
dataGridView1.Rows[i].Cells[5].Value = Convert.ToInt32(dataGridView1.Rows[i - 1].Cells[5].Value) + Convert.ToInt32(dataGridView1.Rows[i].Cells[1].Value) + Convert.ToInt32(dataGridView1.Rows[i].Cells[4].Value);
dataGridView1.Rows[i-1].Cells[6].Value = Convert.ToInt32(dataGridView1.Rows[i-1].Cells[6].Value) + Convert.ToInt32(dataGridView1.Rows[i].Cells[1].Value) + Convert.ToInt32(dataGridView1.Rows[i].Cells[4].Value);
}
}
Reply
Answers (
3
)
development versus production access
How to join two joined tables with inner query in linq?