ここでは、このdatagridview
で、同様の部門の合計を計算したいと思います。
これは、部門が 1 行目の建築で、そのTMH
下の値のセルdatagridview
が 36 の場合です。
次に、2 行目の私の部門はデザインで、TMH セルの値は 45 です。
そして再び、3 行目の建築部門を選択したところ、その TMH 値は現在 45 です。
これが私のコードです
private void ProjectActivitiesGrid_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
Decimal sum = 0;
#region THM CALCULATION.
int column = ProjectActivitiesGrid.CurrentCell.ColumnIndex;
string headerText = ProjectActivitiesGrid.Columns[column].HeaderText;
DataGridViewRow d = this.ProjectActivitiesGrid.Rows[e.RowIndex];
String department = d.Cells[0].Value.ToString();
String chk = m_Project.projdepthrs.Where(c => c.DEPARTMENT == department).Select(c => c.DEPARTMENT).FirstOrDefault();
if (chk == null)
{
MessageBox.Show("Please fill up department alloted hrs first");
d.Cells[1].ReadOnly = true;
d.Cells[2].ReadOnly = true;
d.Cells[3].ReadOnly = true;
d.Cells[4].ReadOnly = true;
d.Cells[5].ReadOnly = true;
d.Cells[6].ReadOnly = true;
d.Cells[7].ReadOnly = true;
}
else
{
d.Cells[1].ReadOnly = false;
d.Cells[2].ReadOnly = false;
d.Cells[3].ReadOnly = false;
d.Cells[4].ReadOnly = false;
d.Cells[5].ReadOnly = false;
d.Cells[6].ReadOnly = false;
d.Cells[7].ReadOnly = false;
String tmh = m_Project.projdepthrs.Where(c => c.DEPARTMENT == department).Select(c => c.TMH).First();
LBLAllotedhrs.Text = tmh;
LBLLefthrs.Text = tmh;
}
foreach (DataGridViewRow rw in ProjectActivitiesGrid.Rows)
{
if (department == d.Cells[0].Value.ToString())
sum = sum + Convert.ToInt32(d.Cells[5].Value);
else
sum = 0;
}
LBLLefthrs.Text = (Convert.ToInt32(LBLLefthrs.Text) - Convert.ToInt32(sum)).ToString();
#endregion
}
次に、同様の部門ドロップダウンリストを持つ1行目と3行目の合計を36 + 45として取得するにはどうすればよいですか。
この状況のロジックが必要です。