简体   繁体   English

C# DataGridView 与 DataSet 显示问题

[英]C# DataGridView with DataSet display issue

I have the following code:我有以下代码:

private void Timer1Tick(object sender, EventArgs e)
{
  timer_ScanTimer.Enabled = false;

  var psc = new ParseScannedCheckNumbers();
  if (psc.ParseCheck(_checkData))
  {
    label_Status.Text = @"Scan Next Check";

    var ct = checkTrans.IndividualCheck.NewIndividualCheckRow();
    ct.Date = DateTime.Now.ToShortDateString();
    var bracct = GetBranchAccountNumber(psc.BankAccountNumber);
    if (bracct.Trim().Length == 7)
    {
      ct.Branch = bracct.Substring(0, 2);
      ct.AccountNumber = bracct.Substring(2, 5);
      ct.NameOnCheck = GetAccountName(ct.Branch + ct.AccountNumber);
      ct.AccountBalance = GetAccountBalance(ct.Branch + ct.AccountNumber);
    }
    else
    {
      ct.Branch = Configuration.Branch;
      ct.AccountNumber = string.Empty;
      ct.NameOnCheck = string.Empty;
      ct.AccountBalance = 0;
    }

    ct.CheckAmount = 0;
    ct.BankRoutingNumber = psc.BankRoutingNumber;
    ct.BankAccountNumber = psc.BankAccountNumber;
    ct.CheckNumber = psc.CheckNumber;
    ct.Status = "Entered";
    checkTrans.IndividualCheck.Rows.Add(ct);
  }
  else
  {
    label_Status.Text = Resources.ScanCheck_ScanFailed;
  }
  _checkData = string.Empty;

  var rs = new RegistrySettings();
  if (!rs.ScanChecksContinuous)
  {
    StopScanning();
    label_Status.Text = Resources.ScanCheck_Success;
    EditLastRowEntered();
  }

  label_ChecksScanned.Text = (dgv_Checks.RowCount - 1).ToString();
}

When the timer goes off, I verified that I have received all of the data, then I add it to the dataset.当计时器关闭时,我确认我已收到所有数据,然后将其添加到数据集中。 It's being added to the dataset without issue, it's just being seen on the datagridview every time.它被毫无问题地添加到数据集中,每次都在 datagridview 上看到它。 Sometimes it works, most time it doesn't.有时它有效,大多数时候它不起作用。

How do I get the datagridview to update when changes are done to the dataset?对数据集进行更改后,如何让 datagridview 更新? Am I doing something wrong in the above code?我在上面的代码中做错了吗?

Thanks!谢谢! (again) (再次)

If you created the dataset and attached it to the DataGridView using the Visual Studio Data Source Configuration Wizard, then you probably have a call to如果您使用 Visual Studio 数据源配置向导创建了数据集并将其附加到DataGridView ,那么您可能需要调用

this.somethingTableAdapter.Fill(this.yourDataSet.someDataTable);

somewhere in your code.在你的代码的某个地方。 This is what actually loads the data from the DataSet into your DataGridView .这就是实际将数据从DataSet加载到DataGridView中的内容。 While calling this method again might not be the 'proper' way to refresh your DGV, it did the job for me.虽然再次调用此方法可能不是刷新 DGV 的“正确”方法,但它为我完成了这项工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM