如果popup = yes,则仅选中复选框

时间:2013-08-02 13:23:15

标签: c# winforms checkbox

我在checkbox中有一个datagridview,我需要一个是/否弹出来确认SQL端的事务。这部分工作正常,但如果我选择NO,复选框仍然会检查。

我如何确保复选框在UI上具有正确的值?

我使用的代码位于cellcontentclick,正确的复选框的代码如下:

if (e.ColumnIndex.ToString() == "3")
{
    DataGridViewCheckBoxCell checkCell = (DataGridViewCheckBoxCell)caseSelectorDataGridView.Rows[e.RowIndex].Cells[3];

    DataGridViewRow row = caseSelectorDataGridView.Rows[e.RowIndex] as DataGridViewRow;

    System.Data.DataRowView SelectedRowView;
    newCityCollectionDataSet.CaseSelectorRow SelectedRow;

    SelectedRowView = (System.Data.DataRowView)caseSelectorBindingSource.Current;
    SelectedRow = (newCityCollectionDataSet.CaseSelectorRow)SelectedRowView.Row;

    DialogResult dialogResult = MessageBox.Show("Are you sure?", "WARNING", MessageBoxButtons.YesNo);
    if (dialogResult == DialogResult.Yes && Convert.ToBoolean(checkCell.Value) == false) 
    {
        if (Convert.ToBoolean(checkCell.Value) == false && caseSelectorDataGridView.IsCurrentCellDirty)
        {
            DataClasses1DataContext dc = new DataClasses1DataContext();

            var matchedCaseNumber = (from c in dc.GetTable<CaseSelector>()
                                     where c.CaseNumberKey == SelectedRow.CaseNumberKey
                                     select c).SingleOrDefault();

            var matchedCaseNumberProp = (from d in dc.GetTable<PropertyInformation>()
                                         where d.CaseNumberKey == SelectedRow.CaseNumberKey
                                         select d).SingleOrDefault();

            DateTime today = DateTime.Now;
            DateTime firstDay = new DateTime(today.Year, today.Month, 1);
            reportsSent newReport = new reportsSent();
            newReport.CaseNumberKey = SelectedRow.CaseNumberKey;
            dc.reportsSents.InsertOnSubmit(newReport);
            matchedCaseNumberProp.DateFinished = DateTime.Now;
            matchedCaseNumberProp.Finished = -1;

            dc.SubmitChanges();

            SelectedRow.FinishedDate = DateTime.Now;
            SelectedRow.FinishedID = Globals.GlobalInt;
            SelectedRow.Finished = -1;

            caseSelectorTableAdapter.Update(newCityCollectionDataSet);

            var qry = dc.PropertyInformations.Where(c => c.DateFinished >= firstDay && c.DateFinished <= today && c.ClientKey == 2).Count();
            var qry1 = dc.PropertyInformations.Where(c => c.DateFinished >= firstDay && c.DateFinished <= today && c.ClientKey == 3).Count();

            txtFinished.Text = Convert.ToString(qry);
            txtGRBFinished.Text = Convert.ToString(qry1);
            txtFinished.Text = Convert.ToString(qry);

            PerformRefresh();
        }
    }
    else if (dialogResult == DialogResult.No)
    {

    }
}

2 个答案:

答案 0 :(得分:1)

假设我已经正确地阅读了这个问题,请尝试:

else if (dialogResult == DialogResult.No)
{
    checkCell.Value = checkCell.FalseValue;
}

答案 1 :(得分:0)

DialogResult dialogResult = MessageBox.Show("Are you sure?", "WARNING", MessageBoxButtons.YesNo);
if (dialogResult == DialogResult.No) return;