-1

我有一个checkboxdatagridview需要一个是/否弹出窗口来确认 SQL 端的事务。这部分工作正常,但如果我选择否,复选框仍会选中。

我将如何确保复选框在 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)
    {

    }
}
4

2 回答 2

1

假设我已正确阅读问题,请尝试:

else if (dialogResult == DialogResult.No)
{
    checkCell.Value = checkCell.FalseValue;
}
于 2013-08-02T13:43:42.853 回答
0
DialogResult dialogResult = MessageBox.Show("Are you sure?", "WARNING", MessageBoxButtons.YesNo);
if (dialogResult == DialogResult.No) return;
于 2013-08-02T15:40:07.657 回答