473,890 Members | 1,411 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(ByV al msg As String) 'Called after serial port has
received data and trimmed the value
CheckForIllegal CrossThreadCall s = 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.In ventory_managem ent_databaseCon nectionString)
cnnInvMan.Open( )

strSQL = "SELECT * FROM Products WHERE ProductIDNumber = '" & msg &
"'"
cmmInvMan = New OleDbCommand(st rSQL, cnnInvMan)
drdTest = cmmInvMan.Execu teReader
Do While drdTest.Read
prodIDNum = CInt(drdTest.It em("ProductID") )
description = drdTest.Item("P roductDescripti on").ToString
loc = drdTest.Item("P roductLocation" ).ToString
minimumOnHand = CInt(drdTest.It em("ReorderLeve l"))
maximumOnHand = CInt(drdTest.It em("MinimumRequ ired"))
Loop

drdTest.Close()

strSQL = "SELECT SUM(UnitsReceiv ed) - SUM(UnitsSold) -
SUM(UnitsShrink age) AS UnitsOnHand " & _
"FROM [" &
Me.Inventory_ma nagement_databa seDataSet.Inven tory_Transactio ns.TableName &
"] WHERE (ProductID = " & prodIDNum & ")"

cmmInvMan = New OleDbCommand(st rSQL, cnnInvMan)
drdTest = cmmInvMan.Execu teReader
Do While drdTest.Read
Try
units = CInt(drdTest.It em("UnitsOnHand "))
Catch ex As InvalidCastExce ption
units = 0
End Try
Loop

drdTest.Close()
cnnInvMan.Close ()

Dim value As Integer
Dim duplicateRow As DataGridViewRow

For Each duplicateRow In Me.DataGridView 1.Rows
If duplicateRow.Ce lls(0).Value Is Nothing Then Exit For
If duplicateRow.Ce lls(0).Value.To String = msg Then
'MessageBox.Sho w(duplicateRow. Cells(1).ToStri ng)
value = CInt(duplicateR ow.Cells(4).Val ue)
value += 1
duplicateRow.Ce lls(4).Value = value.ToString
'unitsScanned
If duplicateRow.Ce lls(1).Value Is Nothing Then 'description
column
duplicateRow.Ce lls(1).Value = description
End If
If duplicateRow.Ce lls(3).Value Is Nothing Then 'UnitsOnHand
duplicateRow.Ce lls(3).Value = units.ToString
End If
If duplicateRow.Ce lls(2).Value Is Nothing Then 'location
duplicateRow.Ce lls(2).Value = loc
End If
If duplicateRow.Ce lls(5).Value Is Nothing Then 'minOnHand
duplicateRow.Ce lls(5).Value = minimumOnHand.T oString
End If
If duplicateRow.Ce lls(6).Value Is Nothing Then 'maxOnHand
duplicateRow.Ce lls(6).Value = maximumOnHand.T oString
End If
Exit Sub
End If
Next

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

TIA,
Tony K.

Jun 27 '08 #1
3 2176
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*********@ki ngprogramming.c omschreef in bericht
news:FD******** *************** ***********@mic rosoft.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(ByV al msg As String) 'Called after serial port has
received data and trimmed the value
CheckForIllegal CrossThreadCall s = 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.In ventory_managem ent_databaseCon nectionString)
cnnInvMan.Open( )

strSQL = "SELECT * FROM Products WHERE ProductIDNumber = '" & msg &
"'"
cmmInvMan = New OleDbCommand(st rSQL, cnnInvMan)
drdTest = cmmInvMan.Execu teReader
Do While drdTest.Read
prodIDNum = CInt(drdTest.It em("ProductID") )
description = drdTest.Item("P roductDescripti on").ToString
loc = drdTest.Item("P roductLocation" ).ToString
minimumOnHand = CInt(drdTest.It em("ReorderLeve l"))
maximumOnHand = CInt(drdTest.It em("MinimumRequ ired"))
Loop

drdTest.Close()

strSQL = "SELECT SUM(UnitsReceiv ed) - SUM(UnitsSold) -
SUM(UnitsShrink age) AS UnitsOnHand " & _
"FROM [" &
Me.Inventory_ma nagement_databa seDataSet.Inven tory_Transactio ns.TableName &
"] WHERE (ProductID = " & prodIDNum & ")"

cmmInvMan = New OleDbCommand(st rSQL, cnnInvMan)
drdTest = cmmInvMan.Execu teReader
Do While drdTest.Read
Try
units = CInt(drdTest.It em("UnitsOnHand "))
Catch ex As InvalidCastExce ption
units = 0
End Try
Loop

drdTest.Close()
cnnInvMan.Close ()

Dim value As Integer
Dim duplicateRow As DataGridViewRow

For Each duplicateRow In Me.DataGridView 1.Rows
If duplicateRow.Ce lls(0).Value Is Nothing Then Exit For
If duplicateRow.Ce lls(0).Value.To String = msg Then
'MessageBox.Sho w(duplicateRow. Cells(1).ToStri ng)
value = CInt(duplicateR ow.Cells(4).Val ue)
value += 1
duplicateRow.Ce lls(4).Value = value.ToString 'unitsScanned
If duplicateRow.Ce lls(1).Value Is Nothing Then
'description column
duplicateRow.Ce lls(1).Value = description
End If
If duplicateRow.Ce lls(3).Value Is Nothing Then
'UnitsOnHand
duplicateRow.Ce lls(3).Value = units.ToString
End If
If duplicateRow.Ce lls(2).Value Is Nothing Then 'location
duplicateRow.Ce lls(2).Value = loc
End If
If duplicateRow.Ce lls(5).Value Is Nothing Then 'minOnHand
duplicateRow.Ce lls(5).Value = minimumOnHand.T oString
End If
If duplicateRow.Ce lls(6).Value Is Nothing Then 'maxOnHand
duplicateRow.Ce lls(6).Value = maximumOnHand.T oString
End If
Exit Sub
End If
Next

Dim row As String() = {msg, description, loc, units.ToString, "1",
minimumOnHand.T oString, maximumOnHand.T oString}
Me.DataGridView 1.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******** *************** ***********@mic rosoft.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*********@ki ngprogramming.c omschreef in bericht
news:FD******** *************** ***********@mic rosoft.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(ByV al msg As String) 'Called after serial port has
received data and trimmed the value
CheckForIllegal CrossThreadCall s = 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
OleDbConnectio n(My.Settings.I nventory_manage ment_databaseCo nnectionString)
cnnInvMan.Open( )

strSQL = "SELECT * FROM Products WHERE ProductIDNumber = '" & msg
& "'"
cmmInvMan = New OleDbCommand(st rSQL, cnnInvMan)
drdTest = cmmInvMan.Execu teReader
Do While drdTest.Read
prodIDNum = CInt(drdTest.It em("ProductID") )
description = drdTest.Item("P roductDescripti on").ToString
loc = drdTest.Item("P roductLocation" ).ToString
minimumOnHand = CInt(drdTest.It em("ReorderLeve l"))
maximumOnHand = CInt(drdTest.It em("MinimumRequ ired"))
Loop

drdTest.Close()

strSQL = "SELECT SUM(UnitsReceiv ed) - SUM(UnitsSold) -
SUM(UnitsShrin kage) AS UnitsOnHand " & _
"FROM [" &
Me.Inventory_m anagement_datab aseDataSet.Inve ntory_Transacti ons.TableName
& "] WHERE (ProductID = " & prodIDNum & ")"

cmmInvMan = New OleDbCommand(st rSQL, cnnInvMan)
drdTest = cmmInvMan.Execu teReader
Do While drdTest.Read
Try
units = CInt(drdTest.It em("UnitsOnHand "))
Catch ex As InvalidCastExce ption
units = 0
End Try
Loop

drdTest.Close()
cnnInvMan.Close ()

Dim value As Integer
Dim duplicateRow As DataGridViewRow

For Each duplicateRow In Me.DataGridView 1.Rows
If duplicateRow.Ce lls(0).Value Is Nothing Then Exit For
If duplicateRow.Ce lls(0).Value.To String = msg Then
'MessageBox.Sho w(duplicateRow. Cells(1).ToStri ng)
value = CInt(duplicateR ow.Cells(4).Val ue)
value += 1
duplicateRow.Ce lls(4).Value = value.ToString 'unitsScanned
If duplicateRow.Ce lls(1).Value Is Nothing Then
'description column
duplicateRow.Ce lls(1).Value = description
End If
If duplicateRow.Ce lls(3).Value Is Nothing Then
'UnitsOnHand
duplicateRow.Ce lls(3).Value = units.ToString
End If
If duplicateRow.Ce lls(2).Value Is Nothing Then 'location
duplicateRow.Ce lls(2).Value = loc
End If
If duplicateRow.Ce lls(5).Value Is Nothing Then 'minOnHand
duplicateRow.Ce lls(5).Value = minimumOnHand.T oString
End If
If duplicateRow.Ce lls(6).Value Is Nothing Then
'maxOnHand
duplicateRow.Ce lls(6).Value = maximumOnHand.T oString
End If
Exit Sub
End If
Next

Dim row As String() = {msg, description, loc, units.ToString, "1",
minimumOnHand. ToString, maximumOnHand.T oString}
Me.DataGridView 1.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.DataTabl e1.NewRow
dr("col1") = firstItemyouret rieved
dr("col2") = nextItemyouretr ieved
dr("col3") = nextnextItem
...
dsData.DataTabl e1.Rows.Add(dr)
...
fill the table with your data
...

datagridview.Da taSource = dsData.DataTabl e1

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
1044
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 (using a scrollable div). One of the columns of the datagridview is Combobox column. Combobox column works fine until there are only a few records in the grid. But for 5000 records it is not showing the comboboxes properly.(Means when scrolling...
3
4664
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 DataGridViewCell 'declare private field _parentDataCell = _parentDataGrid.Rows(rowIndex).Cells(columnIndex) 'set to a specific cell Debug.Print(_parentDataCell.DataGridView.ToString) 'prints:
1
5103
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 form display the data using a data grid view and the add record form creates an object and passes that data to a class method which creates the record using sqlcommand. The add new record form is loaded after the user clicks on the add button on...
0
2981
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 the filter is set i get an IndexOutOfRangeException specifying that the index of the row i have just added does not exist. I have managed to narrow down the conditions that cause the error and it seems to surface if i have a filter set for a...
2
4303
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 checkboxes dont seem to work, and the datagridview throws a dataerror when I try to leave the cell after trying to check/uncheck the checkbox?!
2
6129
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 seems to return an error: "Formatted Value of the cell has wrong type". It works fine when the datagridview's editmode property is
1
6988
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 hang for sometime. I am displaying only 16 rows at a time. I am following the sample mentioned in http://msdn2.microsoft.com/en-us/library/ms171625.aspx artile.
11
76374
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 else who got stumped like I did. It seems so simple... binding a DataGridView to a List<T>. These are the two general problems that I kept running into: (1) When the data in the list updated, the data on the screen did not update. (2) When I...
6
8817
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, the SelectionChanged event fires and I load some more data that's particular to that row. The problem I'm having is that the SelectionChanged event is going way
0
9978
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9822
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10923
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10462
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9633
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7169
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5851
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
4271
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3277
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.