473,408 Members | 1,854 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

DataGridView causing problems

VB 2005 - Windows Vista

I have a form that seems to lock up when the number of rows exceed the
height of the datagridview. The following code executes when data is
received through the serial port (ie. barcode scanning). It seems that
everything works GREAT and processes as it was meant to be until the rows
exceed the display area. I have 7 columns. The Description column is the
only column with the AutoSizeMode set to Fill. The datagridview is docked
to the top. DataSource and DataMember for the DGV is not set to any
dataset.

I have the vertical scrollbar property set but it does not show up most of
the time. When/If it does, when I try and utilize the scrollbar, it locks
up the application immediately. I don't understand but I think it has to do
with the following method.
Sub ReceiveData(ByVal msg As String) 'Called after serial port has
received data and trimmed the value
CheckForIllegalCrossThreadCalls = False
description = Nothing 'form instance variable
loc = Nothing
Dim cmmInvMan As OleDbCommand
Dim strSQL As String
Dim drdTest As OleDbDataReader
Dim cnnInvMan As OleDbConnection = New
OleDbConnection(My.Settings.Inventory_management_d atabaseConnectionString)
cnnInvMan.Open()

strSQL = "SELECT * FROM Products WHERE ProductIDNumber = '" & msg &
"'"
cmmInvMan = New OleDbCommand(strSQL, cnnInvMan)
drdTest = cmmInvMan.ExecuteReader
Do While drdTest.Read
prodIDNum = CInt(drdTest.Item("ProductID"))
description = drdTest.Item("ProductDescription").ToString
loc = drdTest.Item("ProductLocation").ToString
minimumOnHand = CInt(drdTest.Item("ReorderLevel"))
maximumOnHand = CInt(drdTest.Item("MinimumRequired"))
Loop

drdTest.Close()

strSQL = "SELECT SUM(UnitsReceived) - SUM(UnitsSold) -
SUM(UnitsShrinkage) AS UnitsOnHand " & _
"FROM [" &
Me.Inventory_management_databaseDataSet.Inventory_ Transactions.TableName &
"] WHERE (ProductID = " & prodIDNum & ")"

cmmInvMan = New OleDbCommand(strSQL, cnnInvMan)
drdTest = cmmInvMan.ExecuteReader
Do While drdTest.Read
Try
units = CInt(drdTest.Item("UnitsOnHand"))
Catch ex As InvalidCastException
units = 0
End Try
Loop

drdTest.Close()
cnnInvMan.Close()

Dim value As Integer
Dim duplicateRow As DataGridViewRow

For Each duplicateRow In Me.DataGridView1.Rows
If duplicateRow.Cells(0).Value Is Nothing Then Exit For
If duplicateRow.Cells(0).Value.ToString = msg Then
'MessageBox.Show(duplicateRow.Cells(1).ToString)
value = CInt(duplicateRow.Cells(4).Value)
value += 1
duplicateRow.Cells(4).Value = value.ToString
'unitsScanned
If duplicateRow.Cells(1).Value Is Nothing Then 'description
column
duplicateRow.Cells(1).Value = description
End If
If duplicateRow.Cells(3).Value Is Nothing Then 'UnitsOnHand
duplicateRow.Cells(3).Value = units.ToString
End If
If duplicateRow.Cells(2).Value Is Nothing Then 'location
duplicateRow.Cells(2).Value = loc
End If
If duplicateRow.Cells(5).Value Is Nothing Then 'minOnHand
duplicateRow.Cells(5).Value = minimumOnHand.ToString
End If
If duplicateRow.Cells(6).Value Is Nothing Then 'maxOnHand
duplicateRow.Cells(6).Value = maximumOnHand.ToString
End If
Exit Sub
End If
Next

Dim row As String() = {msg, description, loc, units.ToString, "1",
minimumOnHand.ToString, maximumOnHand.ToString}
Me.DataGridView1.Rows.Add(row)
End Sub

TIA,
Tony K.

Jun 27 '08 #1
3 2148
Tony,

Try to avoid working direct with the DataGridView. That is only a UI, not a
datacollection.

Use datasources where for VB 2005 and the DataGridView the datatable is in
my idea the best and use for retrieving Data the dataadapter (or
tableadabter) as those give you the best performance.

Work then direct in the underlying DataSource (DataTable)

Be aware that setting something to nothing is a little bit strange.
Try to declare as less global as possible, because a unnecessary global
variable gives only confusion and uses more memory.

Cor

"Tony K" <my*********@kingprogramming.comschreef in bericht
news:FD**********************************@microsof t.com...
VB 2005 - Windows Vista

I have a form that seems to lock up when the number of rows exceed the
height of the datagridview. The following code executes when data is
received through the serial port (ie. barcode scanning). It seems that
everything works GREAT and processes as it was meant to be until the rows
exceed the display area. I have 7 columns. The Description column is the
only column with the AutoSizeMode set to Fill. The datagridview is docked
to the top. DataSource and DataMember for the DGV is not set to any
dataset.

I have the vertical scrollbar property set but it does not show up most of
the time. When/If it does, when I try and utilize the scrollbar, it locks
up the application immediately. I don't understand but I think it has to
do with the following method.
Sub ReceiveData(ByVal msg As String) 'Called after serial port has
received data and trimmed the value
CheckForIllegalCrossThreadCalls = False
description = Nothing 'form instance variable
loc = Nothing
Dim cmmInvMan As OleDbCommand
Dim strSQL As String
Dim drdTest As OleDbDataReader
Dim cnnInvMan As OleDbConnection = New
OleDbConnection(My.Settings.Inventory_management_d atabaseConnectionString)
cnnInvMan.Open()

strSQL = "SELECT * FROM Products WHERE ProductIDNumber = '" & msg &
"'"
cmmInvMan = New OleDbCommand(strSQL, cnnInvMan)
drdTest = cmmInvMan.ExecuteReader
Do While drdTest.Read
prodIDNum = CInt(drdTest.Item("ProductID"))
description = drdTest.Item("ProductDescription").ToString
loc = drdTest.Item("ProductLocation").ToString
minimumOnHand = CInt(drdTest.Item("ReorderLevel"))
maximumOnHand = CInt(drdTest.Item("MinimumRequired"))
Loop

drdTest.Close()

strSQL = "SELECT SUM(UnitsReceived) - SUM(UnitsSold) -
SUM(UnitsShrinkage) AS UnitsOnHand " & _
"FROM [" &
Me.Inventory_management_databaseDataSet.Inventory_ Transactions.TableName &
"] WHERE (ProductID = " & prodIDNum & ")"

cmmInvMan = New OleDbCommand(strSQL, cnnInvMan)
drdTest = cmmInvMan.ExecuteReader
Do While drdTest.Read
Try
units = CInt(drdTest.Item("UnitsOnHand"))
Catch ex As InvalidCastException
units = 0
End Try
Loop

drdTest.Close()
cnnInvMan.Close()

Dim value As Integer
Dim duplicateRow As DataGridViewRow

For Each duplicateRow In Me.DataGridView1.Rows
If duplicateRow.Cells(0).Value Is Nothing Then Exit For
If duplicateRow.Cells(0).Value.ToString = msg Then
'MessageBox.Show(duplicateRow.Cells(1).ToString)
value = CInt(duplicateRow.Cells(4).Value)
value += 1
duplicateRow.Cells(4).Value = value.ToString 'unitsScanned
If duplicateRow.Cells(1).Value Is Nothing Then
'description column
duplicateRow.Cells(1).Value = description
End If
If duplicateRow.Cells(3).Value Is Nothing Then
'UnitsOnHand
duplicateRow.Cells(3).Value = units.ToString
End If
If duplicateRow.Cells(2).Value Is Nothing Then 'location
duplicateRow.Cells(2).Value = loc
End If
If duplicateRow.Cells(5).Value Is Nothing Then 'minOnHand
duplicateRow.Cells(5).Value = minimumOnHand.ToString
End If
If duplicateRow.Cells(6).Value Is Nothing Then 'maxOnHand
duplicateRow.Cells(6).Value = maximumOnHand.ToString
End If
Exit Sub
End If
Next

Dim row As String() = {msg, description, loc, units.ToString, "1",
minimumOnHand.ToString, maximumOnHand.ToString}
Me.DataGridView1.Rows.Add(row)
End Sub

TIA,
Tony K.
Jun 27 '08 #2
Thank you Cor. I'll make the changes.

Tony K.

"Cor Ligthert[MVP]" <no************@planet.nlwrote in message
news:3D**********************************@microsof t.com...
Tony,

Try to avoid working direct with the DataGridView. That is only a UI, not
a datacollection.

Use datasources where for VB 2005 and the DataGridView the datatable is in
my idea the best and use for retrieving Data the dataadapter (or
tableadabter) as those give you the best performance.

Work then direct in the underlying DataSource (DataTable)

Be aware that setting something to nothing is a little bit strange.
Try to declare as less global as possible, because a unnecessary global
variable gives only confusion and uses more memory.

Cor

"Tony K" <my*********@kingprogramming.comschreef in bericht
news:FD**********************************@microsof t.com...
>VB 2005 - Windows Vista

I have a form that seems to lock up when the number of rows exceed the
height of the datagridview. The following code executes when data is
received through the serial port (ie. barcode scanning). It seems that
everything works GREAT and processes as it was meant to be until the rows
exceed the display area. I have 7 columns. The Description column is
the only column with the AutoSizeMode set to Fill. The datagridview is
docked to the top. DataSource and DataMember for the DGV is not set to
any dataset.

I have the vertical scrollbar property set but it does not show up most
of the time. When/If it does, when I try and utilize the scrollbar, it
locks up the application immediately. I don't understand but I think it
has to do with the following method.
Sub ReceiveData(ByVal msg As String) 'Called after serial port has
received data and trimmed the value
CheckForIllegalCrossThreadCalls = False
description = Nothing 'form instance variable
loc = Nothing
Dim cmmInvMan As OleDbCommand
Dim strSQL As String
Dim drdTest As OleDbDataReader
Dim cnnInvMan As OleDbConnection = New
OleDbConnection(My.Settings.Inventory_management_ databaseConnectionString)
cnnInvMan.Open()

strSQL = "SELECT * FROM Products WHERE ProductIDNumber = '" & msg
& "'"
cmmInvMan = New OleDbCommand(strSQL, cnnInvMan)
drdTest = cmmInvMan.ExecuteReader
Do While drdTest.Read
prodIDNum = CInt(drdTest.Item("ProductID"))
description = drdTest.Item("ProductDescription").ToString
loc = drdTest.Item("ProductLocation").ToString
minimumOnHand = CInt(drdTest.Item("ReorderLevel"))
maximumOnHand = CInt(drdTest.Item("MinimumRequired"))
Loop

drdTest.Close()

strSQL = "SELECT SUM(UnitsReceived) - SUM(UnitsSold) -
SUM(UnitsShrinkage) AS UnitsOnHand " & _
"FROM [" &
Me.Inventory_management_databaseDataSet.Inventory _Transactions.TableName
& "] WHERE (ProductID = " & prodIDNum & ")"

cmmInvMan = New OleDbCommand(strSQL, cnnInvMan)
drdTest = cmmInvMan.ExecuteReader
Do While drdTest.Read
Try
units = CInt(drdTest.Item("UnitsOnHand"))
Catch ex As InvalidCastException
units = 0
End Try
Loop

drdTest.Close()
cnnInvMan.Close()

Dim value As Integer
Dim duplicateRow As DataGridViewRow

For Each duplicateRow In Me.DataGridView1.Rows
If duplicateRow.Cells(0).Value Is Nothing Then Exit For
If duplicateRow.Cells(0).Value.ToString = msg Then
'MessageBox.Show(duplicateRow.Cells(1).ToString)
value = CInt(duplicateRow.Cells(4).Value)
value += 1
duplicateRow.Cells(4).Value = value.ToString 'unitsScanned
If duplicateRow.Cells(1).Value Is Nothing Then
'description column
duplicateRow.Cells(1).Value = description
End If
If duplicateRow.Cells(3).Value Is Nothing Then
'UnitsOnHand
duplicateRow.Cells(3).Value = units.ToString
End If
If duplicateRow.Cells(2).Value Is Nothing Then 'location
duplicateRow.Cells(2).Value = loc
End If
If duplicateRow.Cells(5).Value Is Nothing Then 'minOnHand
duplicateRow.Cells(5).Value = minimumOnHand.ToString
End If
If duplicateRow.Cells(6).Value Is Nothing Then
'maxOnHand
duplicateRow.Cells(6).Value = maximumOnHand.ToString
End If
Exit Sub
End If
Next

Dim row As String() = {msg, description, loc, units.ToString, "1",
minimumOnHand.ToString, maximumOnHand.ToString}
Me.DataGridView1.Rows.Add(row)
End Sub

TIA,
Tony K.
Jun 27 '08 #3
Hello,

Instead of trying to display the date you retrieve from the serial port
directly in the datagridview, do this: Create an empty dataset in the
DataSources tab of Visual Studio - next to the Explorer/Solution tab
(usually on the right side of the screen or wherever you have set the
Solution explorer). In the datasources tab just use the wizard to
create an empty dataset and don't select any tables. Once you have an
empty dataset you can then edit the dateset (right click on the new
dataset and select edit from the context menu). Once you are inside the
dataset window - right click and select Add Table. Create a table that
will contains the fields you need - you an assign datatypes, but the
default is string. Name the table something - the default name is
"DataTable1"

Now, in your form code, you can declare a dataset var as the dataset you
just created

Dim dsData As MyNewDataset 'or whatever you name the dataset in the
datasources tab

dsData = New MyNewDataset
Dim dr As DataRow = dsData.DataTable1.NewRow
dr("col1") = firstItemyouretrieved
dr("col2") = nextItemyouretrieved
dr("col3") = nextnextItem
...
dsData.DataTable1.Rows.Add(dr)
...
fill the table with your data
...

datagridview.DataSource = dsData.DataTable1

You can then use the dataAdapter to transfer the data to a server DB.
Note: the dataAdapter doesn't work with an OLEDB db (MS Access) - only
works with Server DBs. For OLEDB you can use an ADO.Net command object
- works almost the same as classic ADO command object.
Rich

*** Sent via Developersdex http://www.developersdex.com ***
Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ketan Dixit | last post by:
Hi , I am developing a ASP.NET web application in which I am using a datagridview. It is an editable gridview. My grid has almost 5000 items and i am required to show these items in a single page...
3
by: Daniel Manes | last post by:
I need a strategy to debug this situation... I can't put all the code involved, but here are some of the critical lines with comments: ------------------------- Private _parentDataCell As...
1
by: romerve | last post by:
Hello; i am having some problems trying to get a form that has a datagridview to refresh after a new record is created. I have a MDI container and menu form and add new record form; the menu...
0
by: =?Utf-8?B?aW1yYW4uYQ==?= | last post by:
Hi all, I am having a problem with inserting rows in to my datagridview control. The datagridview is bound to a bindingsource with a filter set. If i try and add a row to the datagridview while...
2
by: mrstrong | last post by:
Gday, I have a datagridview that I am creating the columns programatically which all seems to work fine. I have a couple of dropdown boxes, so I have set the editMode= EditOnEnter. Now my...
2
by: mrstrong | last post by:
Gday, Why would all my checkboxes inside a datagridview stop working (ie checked state not updating when user clicks) when the datagridview's editmode property is changed to "EditOnEnter"? It...
1
by: slg | last post by:
I am using virtual mode for datagrid. After i set the rowcount property to 16000, I am receiving datagridview 's CellValueNeeded event 16000 times for each row. This is causing the application to...
11
by: dave18 | last post by:
Hello all! I found a solution to my original question, but there's still so much I don't understand about it, I thought I'd give this forum a try. At the very least, maybe it will help someone...
6
by: Simon Harvey | last post by:
Hi all, I'm really hoping someone can help me with this as it's causing me some serious problems. I have a Windows Forms application using the gridview control. When the user selects a row,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.