| ItemName | Category | 1st floor | 2nd floor | total |
| Bedsheet | ||||
| wash | 1 | 4 | ? | |
| fresh | 3 | 5 | ? | |
| alter | 8 | 6 | ? | |
| condemn | 7 | 5 | ? | |
| sub-total | ? | ? | ||
| pillow cover | wash | 8 | 4 | ? |
| fresh | 2 | 3 | ? | |
| alter | 8 | 8 | ? | |
| condemn | 3 | 4 | ? | |
| sub-total | ? | ? | ||
| so on |
This is a MSVS 2005 WINDOWS FORM APPLICATION. In this windows form application, I have datagridview and a show button, on clicking the show button data gets uploaded in the datagridview and this is the dynamic data from sql 2005 table which I am getting through a datatable I have created. Now my problem is how to calculate and get sub-total and Total figures in the above dynamic datagridview. please reply as soon as possible.
alan kumarPosted Feb 27, 2014, 4:07 AM
if (dt_temp.Rows.Count > 0)
{
System.Data.DataTable dt_temp1 = GetDistintColumnsRowValues(dt_report, "dept_code");
System.Data.DataTable dt_temp2 = GetDistintColumnsRowValues(dt_report, "sub_loc_code");
if (dt_temp1.Rows.Count > 0 && dt_temp2.Rows.Count > 0)
{
for (int i = 0; i <= dt_temp.Rows.Count; i++)
{
if (dt.Rows.Count > 0)
{
row = dt.NewRow();
row["Item Name"] = "Sub_total";
for (int n = 0; n < dt_temp1.Rows.Count; n++)
{
int total = 0;
string colname = dt_temp1.Rows[n]["dept_name"].ToString(); ;
string dept_name = dt_temp1.Rows[n]["dept_code"].ToString();
sub_item_code = dt_temp.Rows[i - 1]["item_code"].ToString();
dt_sub_total.DefaultView.RowFilter = "item_code = '" + sub_item_code + "' and dept_code = '" + dept_name + "'";
dt_sub_filter = dt_sub_total.DefaultView.ToTable();
if (dt_sub_filter.Rows.Count > 0)
{
row[colname] = dt_sub_filter.Rows[0]["total"].ToString();
}
}
dt.Rows.Add(row);
if (i == dt_temp.Rows.Count)
{
break;
}
}
row = dt.NewRow();
row["Item Name"] = dt_temp.Rows[i]["item_desc"].ToString();
dt.Rows.Add(row);
item_code = dt_temp.Rows[i]["item_code"].ToString();
for (int k = 0; k < dt_temp2.Rows.Count; k++)
{
row = dt.NewRow();
row["Category"] = dt_temp2.Rows[k]["loc_desc"].ToString();
for (int j = 0; j < dt_temp1.Rows.Count; j++)
{
dept_code = dt_temp1.Rows[j]["dept_code"].ToString();
sub_loc_code = dt_temp2.Rows[k]["sub_loc_code"].ToString();
dt_report.DefaultView.RowFilter = "item_code = '" + item_code + "' and dept_code = '" + dept_code + "' and sub_loc_code = '" + sub_loc_code + "'";
dt_filter = dt_report.DefaultView.ToTable();
if (dt_filter.Rows.Count > 0)
{
string columnname = dt_temp1.Rows[j]["dept_name"].ToString();
if (dt.Columns.Contains(columnname))
{
row[columnname] = dt_filter.Rows[0]["curr_qty"].ToString();
}
else
{
dt.Columns.Add(columnname);
row[columnname] = dt_filter.Rows[0]["curr_qty"].ToString();
}
}
if (j == dt_temp1.Rows.Count - 1)
{
dt_main_total.DefaultView.RowFilter = "item_code = '" + item_code + "' and sub_loc_code = '" + sub_loc_code + "'";
dt_main_filter = dt_main_total.DefaultView.ToTable();
if (dt_main_filter.Rows.Count > 0)
{
if (dt.Columns.Contains("Total1"))
{
row["Total1"] = dt_main_filter.Rows[0]["tot"].ToString();
}
else
{
dt.Columns.Add("Total1");
row["Total1"] = dt_main_filter.Rows[0]["tot"].ToString();
}
}
}
}
dt.Rows.Add(row);
}
}
}
}
Nihal AhmedPosted Feb 24, 2014, 7:58 AM
how u have done...
alan kumarPosted Feb 15, 2014, 5:52 AM