title: Strange issue with Datagridview-Rows not displayed
body: <p>I have a Datagridview connected to a dataset.The problem is that occasionally,when the data is refreshed,it is not displayed in the DGV.The code is:</p>
  
  <pre><code>Private Sub DisplayInDGV()
      Dim SQLSet As String
      Dim DASet As New OleDb.OleDbDataAdapter
      Dim DSSet As New DataSet
      SQLSet = "Select * From SetDisplayTable"
  
      DASet = New OleDb.OleDbDataAdapter(SQLSet, Con)
      DSSet.Clear()
      DASet.Fill(DSSet, "DSSetHere")
      With DGVSetView
  
          .Refresh()
          .AutoGenerateColumns = False   
          .DataSource = Nothing
          .DataSource = DSSet.Tables(0)
  
          .Update()
         DGVSetView.Columns(i).DataPropertyName = DSSet.Tables(0).Columns(i).ToString
  
          .Columns(0).DataPropertyName = DSSet.Tables(0).Columns(0).ToString
          .Columns(2).DataPropertyName = DSSet.Tables(0).Columns(1).ToString
          .Columns(3).DataPropertyName = DSSet.Tables(0).Columns(2).ToString
          .Columns(4).DataPropertyName = DSSet.Tables(0).Columns(3).ToString
          .Columns(5).DataPropertyName = DSSet.Tables(0).Columns(4).ToString
          .Columns(6).DataPropertyName = DSSet.Tables(0).Columns(5).ToString
          .Columns(7).DataPropertyName = DSSet.Tables(0).Columns(6).ToString
          .Columns(8).DataPropertyName = DSSet.Tables(0).Columns(7).ToString
          .Columns(9).DataPropertyName = DSSet.Tables(0).Columns(8).ToString
          .Columns(10).DataPropertyName = DSSet.Tables(0).Columns(9).ToString
          .Columns(11).DataPropertyName = DSSet.Tables(0).Columns(10).ToString 'Item Unique Code for Hot Edit
          .Columns(14).DataPropertyName = DSSet.Tables(0).Columns(12).ToString
      End With
      'Updating Totals/::
      For ItemRow As Integer = 0 To DGVSetView.Rows.Count - 1
          If DGVSetView.Rows(ItemRow).Cells(14).Value = True Then
              DGVSetView.Rows(ItemRow).Cells(12).Value = DGVSetView.Rows(ItemRow).Cells(10).Value
          ElseIf DGVSetView.Rows(ItemRow).Cells(14).Value = False Then
              DGVSetView.Rows(ItemRow).Cells(13).Value = DGVSetView.Rows(ItemRow).Cells(10).Value
  
          End If
      Next
      'Updating School and general totals in DGV//:
      Dim SchoolTotal, GeneralTotal As Decimal
      For ColumnTotal As Integer = 0 To DGVSetView.Rows.Count - 1
  
          SchoolTotal += DGVSetView.Rows(ColumnTotal).Cells(12).Value
          GeneralTotal += DGVSetView.Rows(ColumnTotal).Cells(13).Value
      Next
      txtSchoolAmtFinal.Text = SchoolTotal
      txtGeneralAmtFinal.Text = GeneralTotal
  
      DGVSetView.Update()
      'Get gross total of the DGV amount column//:
      If DGVSetView.RowCount &lt;&gt; 0 Then
          Dim GrossAmt As Decimal = 0
  
          For Index As Integer = 0 To DGVSetView.RowCount - 1
              '  GrossAmt += Convert.ToDecimal(DataGridView1.Rows(Index).Cells(11).Value)
              If Str(DGVSetView.Rows(Index).Cells(10).Value) = "Null" Or (DGVSetView.Rows(Index).Cells(10).Value) &lt;= 0 Then
                  MsgBox("Item Number " &amp; (DGVSetView.Rows(Index).Cells(10).Value) &amp; " is either blank or 0", MsgBoxStyle.Exclamation, "Item Error")
              Else
                  GrossAmt += Convert.ToDecimal(DGVSetView.Rows(Index).Cells(10).Value)
              End If
          Next
          txtInsertGrossAmt.Text = GrossAmt ' - Val(DGVSetView.Text)
          Call SetNetAmount()
      End If
      'Generate Serial//:
      Dim X As Integer
      Do While X &lt; DGVSetView.Rows.Count
          DGVSetView.Item(0, X).Value = X + 1
          X = X + 1
      Loop
      'Disbaling editing in all columns except pending//:
      With DGVSetView
          .Columns(0).ReadOnly = True
          .Columns(2).ReadOnly = True
          .Columns(3).ReadOnly = True
          .Columns(4).ReadOnly = True
          .Columns(5).ReadOnly = True
          .Columns(6).ReadOnly = True
          .Columns(7).ReadOnly = True
          .Columns(8).ReadOnly = True
          .Columns(9).ReadOnly = True
          .Columns(10).ReadOnly = True
      End With
      txtTotalItems.Text = DGVSetView.Rows.Count
      For Each r As DataGridViewRow In DGVSetView.Rows
          r.Cells(1).Value = True
      Next r
  End Sub
  </code></pre>
  
  <p>The problem is that occasionally,the DGV will not show any rows and displays a blank frame.At such instances.if I check in     DGV.Rows.count 
  the result is 0 despite there being underlying data in the table.
  Note that this happens randomly.At other times the DGV refreshed properly and also displays data correctly.
  Also note that this DGV resides within a TabControl.
  Further,when the DGV fails to display the data,the totals which I have calculated in the above sub procedure return zero value.As such the problem appears to lie somewhere in the rows not being inserted in the DGV.
  Thank you.</p>
  
  <p>Khalid.
  //Edit;Code Updated:
  @jmcilhinney I have updated my code as follows.However,the earlier problem of the DGV going blank occasionally persists.Also the update process has slowed down slightly.It seems I may be making a mistake in the location of placing the Suspend and ResumeBinding statements:</p>
  
  <pre><code>Private Sub SetPreview()
      Dim SQLSet As String
      Dim DASet As New OleDb.OleDbDataAdapter
      Dim DSSet As New DataSet
      SQLSet = "Select * From SetDisplayTable"
      Dim DTDGV As New DataTable
      Dim DGVBindingSource As New BindingSource
      DASet = New OleDb.OleDbDataAdapter(SQLSet, Con)
  
      DASet.Fill(DTDGV)
      DGVBindingSource.DataSource = DTDGV     
      DGVBindingSource.ResumeBinding()
  
      With DGVSetView
          .AutoGenerateColumns = False
          .DataSource = DGVBindingSource
          .Columns(0).DataPropertyName = DTDGV.Columns(0).ToString
          .Columns(2).DataPropertyName = DTDGV.Columns(1).ToString
          .Columns(3).DataPropertyName = DTDGV.Columns(2).ToString
          .Columns(4).DataPropertyName = DTDGV.Columns(3).ToString
          .Columns(5).DataPropertyName = DTDGV.Columns(4).ToString
          .Columns(6).DataPropertyName = DTDGV.Columns(5).ToString
          .Columns(7).DataPropertyName = DTDGV.Columns(6).ToString
          .Columns(8).DataPropertyName = DTDGV.Columns(7).ToString
          .Columns(9).DataPropertyName = DTDGV.Columns(8).ToString
          .Columns(10).DataPropertyName = DTDGV.Columns(9).ToString
          .Columns(11).DataPropertyName = DTDGV.Columns(10).ToString 'Item Unique Code for Hot Edit
          .Columns(14).DataPropertyName = DTDGV.Columns(12).ToString
      End With
  
      DGVBindingSource.SuspendBinding()
  
      'Updating Totals/::
      For ItemRow As Integer = 0 To DGVSetView.Rows.Count - 1
          If DGVSetView.Rows(ItemRow).Cells(14).Value = True Then
              DGVSetView.Rows(ItemRow).Cells(12).Value = DGVSetView.Rows(ItemRow).Cells(10).Value
          ElseIf DGVSetView.Rows(ItemRow).Cells(14).Value = False Then
              DGVSetView.Rows(ItemRow).Cells(13).Value = DGVSetView.Rows(ItemRow).Cells(10).Value
  
          End If
      Next
  
      'Updating School and general totals in DGV//:
      Dim SchoolTotal, GeneralTotal As Decimal
      For ColumnTotal As Integer = 0 To DGVSetView.Rows.Count - 1
  
          SchoolTotal += DGVSetView.Rows(ColumnTotal).Cells(12).Value
          GeneralTotal += DGVSetView.Rows(ColumnTotal).Cells(13).Value
      Next
      txtSchoolAmtFinal.Text = SchoolTotal
      txtGeneralAmtFinal.Text = GeneralTotal
  
      DGVSetView.Update()
      'Get gross total of the DGV amount column//:
      If DGVSetView.RowCount &lt;&gt; 0 Then
          Dim GrossAmt As Decimal = 0
  
          For Index As Integer = 0 To DGVSetView.RowCount - 1
              '  GrossAmt += Convert.ToDecimal(DataGridView1.Rows(Index).Cells(11).Value)
              If Str(DGVSetView.Rows(Index).Cells(10).Value) = "Null" Or (DGVSetView.Rows(Index).Cells(10).Value) &lt;= 0 Then
                  MsgBox("Item Number " &amp; (DGVSetView.Rows(Index).Cells(10).Value) &amp; " is either blank or 0", MsgBoxStyle.Exclamation, "Item Error")
              Else
                  GrossAmt += Convert.ToDecimal(DGVSetView.Rows(Index).Cells(10).Value)
              End If
          Next
          txtInsertGrossAmt.Text = GrossAmt ' - Val(DGVSetView.Text)
          Call SetNetAmount()
      End If
  
      'Disabling editing in all columns except pending//:
      With DGVSetView
          .Columns(0).ReadOnly = True
          .Columns(2).ReadOnly = True
          .Columns(3).ReadOnly = True
          .Columns(4).ReadOnly = True
          .Columns(5).ReadOnly = True
          .Columns(6).ReadOnly = True
          .Columns(7).ReadOnly = True
          .Columns(8).ReadOnly = True
          .Columns(9).ReadOnly = True
          .Columns(10).ReadOnly = True
      End With
      txtTotalItems.Text = DGVSetView.Rows.Count
      For Each r As DataGridViewRow In DGVSetView.Rows
          r.Cells(1).Value = True
      Next r
  
  End Sub
  </code></pre>