Как снять отметку с DataGridViewCheckBoxCell после проверки суммы авторизации? - PullRequest
0 голосов
/ 23 апреля 2020

После нажатия на DataGridViewCheckBoxCell я проверю сумму заказа. Если сумма превышает сумму авторизации, я покажу MessageBox, чтобы сообщить пользователю, что сумма превышает авторизацию. и затем я хочу, чтобы DataGridViewCheckBoxCell не был проверен. Теперь, хотя сумма не будет превышать квоту, но DataGridViewCheckBoxCell все еще проверяется. После того, как я выбрал другую ячейку, она становится непроверенной. Что делать, если я не выбрал другую ячейку, она может автоматически отключиться? Код следующий:

private void gdv_StrategyList_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
    gdv_StrategyList.CommitEdit(DataGridViewDataErrorContexts.Commit);

    int columnCount = gdv_StrategyList.Columns.Count;
    int columnIndex = e.ColumnIndex;
    int rowIndex = e.RowIndex;
    if (columnIndex != columnCount - 1) return;

    DataGridViewCheckBoxCell cbx = gdv_StrategyList.Rows[rowIndex].Cells[columnIndex] as 
    DataGridViewCheckBoxCell;
    cbx.TrueValue = 1;
    cbx.FalseValue = 0;

    double price = 0.0;
    int tradeQuantity = 0;
    bool tmp = double.TryParse(gdv_StrategyList.Rows[rowIndex].Cells[2].Value.ToString(), out price);
    if (!tmp)
    {
        MessageBox.Show("Error Quotation.");
        return;
    }
    tmp = int.TryParse(gdv_StrategyList.Rows[rowIndex].Cells[6].Value.ToString(), out tradeQuantity);
    if (!tmp)
    {
        MessageBox.Show("Order Quantity Must be Integer.");
        return;
    }

    int tradeVolume = (int)(price * (double)tradeQuantity * 1000.0);
    int subAmount = m_subAmount;
    int trdAmountLeft = 0;

    if (Convert.ToBoolean(cbx.Value))
    {
        subAmount += tradeVolume;
    }
    else
    {
        subAmount -= tradeVolume;
    }

    trdAmountLeft = m_authAmount - subAmount;
    if (trdAmountLeft < 0)
    {
        MessageBox.Show("Over the Quota!");
        cbx.Value = false;
    }
    else
    {
        m_trdAmountLeft = trdAmountLeft;
        m_subAmount = subAmount;
        m_trdAmountLeft = m_authAmount - m_subAmount;

        //Update Authorization Table
        updateAuthAmount(m_authAmount, m_subAmount, m_trdAmountLeft);
    }
}

Спасибо.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...