开发者

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.Accoun开发者_如何学JAVAtBalance = 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. Sometimes it works, most time it doesn't.

How do I get the datagridview to update when changes are done to the dataset? 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

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

somewhere in your code. This is what actually loads the data from the DataSet into your DataGridView. While calling this method again might not be the 'proper' way to refresh your DGV, it did the job for me.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜