DataGridView不显示checkboxcolumn的实际值

时间:2019-12-19 20:45:03

标签: c# checkbox data-binding datagridview datasource

我从数据库中读取数据并将其绑定到列表

private void SetDataSource
{
    List<Warehouse> list = ListWarehouse(idINV); // DB query.
    m_WarehouseBindingList = new BindingList<Warehouse>(list);
    m_WarehouseBindingSource.DataSource = m_WarehouseBindingList;
}

将其绑定到DataGridView

private void LoadDataGridView()
{
    if (m_WarehouseBindingSource== null) { return; }
    if (dgWarehouse.DataSource != null)
    {
        dgWarehouse.DataSource = null;
        dgWarehouse.Rows.Clear();
        dgWarehouse.Columns.Clear();
    }
    dgWarehouse.AutoGenerateColumns = true;
    dgWarehouse.DataSource = m_WarehouseBindingSource;
}

然后将DataBinding设置为Textbox(和Checkbox)

private void SetDataBinding()
{

    tbAmount.DataBindings.Clear();
    tbAmount.DataBindings.Add("Text", m_WarehouseBindingSource, "Amount", true, DataSourceUpdateMode.OnPropertyChanged);
    chkCounted.DataBindings.Clear();
    chkCounted.DataBindings.Add("Checked", m_WarehouseBindingList, "Counted", true, DataSourceUpdateMode.OnPropertyChanged);

    _warehouse = null; // Object of class Warehouse.
    _warehouse = (Warehouse)m_WarehouseBindingSource.Current;
}

现在,我在tbAmount中输入一个值并保存数据。

private void tbAmount_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyCode == Keys.Enter)
    {
            if (sender is TextBox)
            {
                TextBox tb = (TextBox)sender;

                var v = new DoubleValidator();
                if (!v.IsValid(tb.Text.ToString()))
                {
                    MessageBox.Show("Enter double value");
                    tb.Focus();
                }
                else
                {
                    try
                    {
                        Cursor.Current = Cursors.WaitCursor;

                        if (_warehouse != null)
                        {
                            SaveAmount(_warehouse.IdINV, _warehouse.Amount, true);
                            m_BestandBindingSource.MoveNext();
                        }
                    }
                    finally
                    {
                        tbAmount.Focus();
                        tbAmount.Text = "";
                        SetDataBinding();
                        Cursor.Current = Cursors.Default;
                    }
                }
            }
        }

    }

现在,我遇到了一个问题,即“已计数”列将不会更新。 对于金额值,一切正常。

怎么了?如何解决问题?

0 个答案:

没有答案