在更改datagridview单元格值时更新标签文本

时间:2013-09-09 16:18:00

标签: c# mysql datagridview

分配的hrs标签是每个部门分配的总小时数,剩余小时数是在小区结束编辑结束时减去分配的小时数。

在Datagridview中,一旦我从下拉列表中选择了department的值并输入了tmh cell的值,然后在cellend编辑行,我必须更新左边的hrs标签文本,但我没有得到这种情况的逻辑。

enter image description here

这是我的代码

        #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();

        if (department != null)
        {

            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;
            }

            if (d.Cells[5].Value != null)
            {

                foreach (DataGridViewRow rw in ProjectActivitiesGrid.Rows)
                {
                    LBLLefthrs.Text = (Convert.ToInt32(LBLLefthrs.Text) - Convert.ToInt32(d.Cells[5].Value)).ToString();
                }
            }
            else
            {
                LBLLefthrs.Text = "";
            }

        }
        else
            MessageBox.Show("please select department");

        #endregion

0 个答案:

没有答案