我有以下用于更新datagridview的代码:
public readonly BindingList<InventoryTransaction> InventoryTransactions = new BindingList<InventoryTransaction>() { RaiseListChangedEvents = true };
private bool _scanning;
private string _checkData;
public BarCodeForm()
{
InitializeComponent();
barCodeForm_InventoryTransactionBindingSource.DataSource = InventoryTransactions;
panel1.Enabled = false;
_scanning = true;
timer_ScanTimer.Enabled = false;
//InventoryTransactions.AddingNew += InventoryTransactions_AddingNew;
}
private void timer_ScanTimer_Tick(object sender, EventArgs e)
{
panel1.Enabled = true;
label_Message.Text = "Please press ENTER or click RESET to scan again.";
timer_ScanTimer.Enabled = false;
textBox_ModelNumber.Text = _checkData;
textBox_Quantity.Text = "1";
var qry = (from x in InventoryTransactions
where x.ModelNumber == _checkData
select x).FirstOrDefault();
_checkData = string.Empty;
if (qry == null)
{
textBox_Quantity.Focus();
return;
}
qry.Quantity += qry.Quantity;
barCodeForm_InventoryTransactionBindingSource.EndEdit();
panel1.Enabled = false;
_scanning = true;
timer_ScanTimer.Enabled = false;
panel1.Text = "Scan now!";
ResetForm();
}
问题是我更新了InventoryTransactions的数量,但我的datagridview没有更新。我是否必须发出某种命令以强制更新或应用更改?
谢谢!