I have a DataGridView that I NEED to display the data that is scanned with a
barcode.
The columns are:
Product Number Description Location Units On Hand Untis Scanned
Min On Hand Max On Hand
All columns are retrieved from the database except Units Scanned. That is
calculated by the # of times the operator scans a barcode.
The code I use for filling the DataGridView is:
Private Sub ReceiveData(ByVal msg As String)
' Receive strings from a serial port.
CheckForIllegalCrossThreadCalls = False
Dim cnnInventory As OleDbConnection
Dim dgvRow(7) As String
Dim cmmInventory As OleDbCommand
Dim dadInventory As OleDbDataAdapter
Dim dtbInventory As DataTable
Dim cmmUnitsOnHand As OleDbCommand
Dim dadUnitsOnHand As OleDbDataAdapter
Dim dtbUnitsOnHand As DataTable
Dim intCounter As Integer, prodID As Integer
'Instantiate and open the connection
cnnInventory = New
OleDbConnection(My.Settings.Inventory_management_d atabaseConnectionString)
cnnInventory.Open()
'Instantiate the command datatable
cmmInventory = New OleDbCommand("SELECT * FROM Products",
cnnInventory)
dtbInventory = New DataTable()
'Instantiate and initialize the data adapter
dadInventory = New OleDbDataAdapter("SELECT * FROM Products",
cnnInventory)
dadInventory.SelectCommand = cmmInventory
'Fill the data table view
dadInventory.Fill(dtbInventory)
'Filter the data table view
dtbInventory.DefaultView.RowFilter = "ProductIDNumber = '" & msg &
"'"
prodID =
CType(dtbInventory.DefaultView(0).Row("ProductID") .ToString, Integer)
dgvRow(0) = msg
dgvRow(1) =
dtbInventory.DefaultView(0).Row("ProductDescriptio n").ToString
dgvRow(2) =
dtbInventory.DefaultView(0).Row("ProductLocation") .ToString
dgvRow(5) = dtbInventory.DefaultView(0).Row("ReorderLevel").To String
dgvRow(6) =
dtbInventory.DefaultView(0).Row("MinimumRequired") .ToString
'Instantiate the command datatable
cmmUnitsOnHand = New OleDbCommand("SELECT SUM(UnitsReceived) -
SUM(UnitsSold) - SUM(UnitsShrinkage) AS UnitsOnHand " & _
"FROM [Inventory Transactions] WHERE (ProductID = " & prodID
& ")", cnnInventory)
dtbUnitsOnHand = New DataTable
'Instantiate and initialize the data adapter
dadUnitsOnHand = New OleDbDataAdapter("SELECT SUM(UnitsReceived) -
SUM(UnitsSold) - SUM(UnitsShrinkage) AS UnitsOnHand " & _
"FROM [Inventory Transactions] WHERE (ProductID = " & prodID
& ")", cnnInventory)
dadUnitsOnHand.SelectCommand = cmmUnitsOnHand
'Fill the data table view
dadUnitsOnHand.Fill(dtbUnitsOnHand)
'Filter the data table view
'dtbUnitsOnHand.DefaultView.RowFilter = "ProductID = " & prodID
For intCounter = 0 To dtbUnitsOnHand.DefaultView.Count - 1
dgvRow(3) =
dtbUnitsOnHand.DefaultView(0).Row("UnitsOnHand").T oString
Next
Me.DataGridView1.Rows.Add(dgvRow)
cnnInventory.Close()
End Sub
For each barcode ProductIDNumber scanned, it retrieves the description,
location, unitsOnHand, minOnHand, maxOnHand.
Problems: When the # of rows exceed the amount displayed, the applications
seems to freeze. Example: I have a maximum of 20 rows that can be
displayed at once, when I have entered 21 different items or more, then try
to scroll on the vertical scroll bar, the application freezes and nothing
else happens. Sometimes the scrollbar is not even displayed but instead it
looks like a bunch of little grid cells.
I have the properties set to show the vertical scroll bar.
There is not a DataSource associated with the DataGridView.
Why does it lock up when there are more rows added than displayed??
Thanks,
Tony K.