When calling my form from within my MDI, I receive this error message.
InvalidOperationException was unhandled
An error occurred creating the form. See Exception.InnerException for
details. The error is: Index was out of range. Must be non-negative and
less than the size of the collection.
Parameter name: index
This error has to do with one line in particular.
Me.Inventory_TransactionsDataGridView.Rows(e.RowIn dex).Cells(0).Value =
Today()
If I rem this line out, the form loads. What I want to do is when a cell in
my DataGridView is changed, insert the date into the 1st column of my DGV.
Here are the first several lines of code:
Private Sub Inventory_TransactionsDataGridView_CellValueChange d(ByVal sender
As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs)
Handles Inventory_TransactionsDataGridView.CellValueChange d
If e.ColumnIndex = 1 Then 'when the part# combo box is changed
(2nd column)
Dim cnnProd As New
OleDbConnection(My.Settings.Inventory_management_d atabaseConnectionString)
'connection used from app settings
Dim cmmProd As OleDbCommand
Dim strSQL As String 'sql statement
Dim description As String
Dim drdProd As OleDbDataReader
Dim prodID As String
Dim unitPrice As Decimal
Me.Inventory_TransactionsDataGridView.Rows(e.RowIn dex).Cells(0).Value
= Today()
The last line is the problem line. In the DataGrid I have default cell
style set as DataGridViewCellStyle { Format=d }
What can I do to correct this exception problem that I am receiving?
Thanks,
Tony K 3 7105
Tony,
Be aware that change events normaly are as well called when controls are
initializing, I would put a check around it to see if the index has a value
(probably it is -1 when initialing however I would look at this if I was you
in the debugger).
Cor
"Tony K" <no************@kingprogramming.comschreef in bericht
news:08**********************************@microsof t.com...
When calling my form from within my MDI, I receive this error message.
InvalidOperationException was unhandled
An error occurred creating the form. See Exception.InnerException for
details. The error is: Index was out of range. Must be non-negative and
less than the size of the collection.
Parameter name: index
This error has to do with one line in particular.
Me.Inventory_TransactionsDataGridView.Rows(e.RowIn dex).Cells(0).Value =
Today()
If I rem this line out, the form loads. What I want to do is when a cell
in my DataGridView is changed, insert the date into the 1st column of my
DGV.
Here are the first several lines of code:
Private Sub Inventory_TransactionsDataGridView_CellValueChange d(ByVal
sender As Object, ByVal e As
System.Windows.Forms.DataGridViewCellEventArgs) Handles
Inventory_TransactionsDataGridView.CellValueChange d
If e.ColumnIndex = 1 Then 'when the part# combo box is changed
(2nd column)
Dim cnnProd As New
OleDbConnection(My.Settings.Inventory_management_d atabaseConnectionString)
'connection used from app settings
Dim cmmProd As OleDbCommand
Dim strSQL As String 'sql statement
Dim description As String
Dim drdProd As OleDbDataReader
Dim prodID As String
Dim unitPrice As Decimal
Me.Inventory_TransactionsDataGridView.Rows(e.RowIn dex).Cells(0).Value =
Today()
The last line is the problem line. In the DataGrid I have default cell
style set as DataGridViewCellStyle { Format=d }
What can I do to correct this exception problem that I am receiving?
Thanks,
Tony K
Yes, that was exactly the problem. e.RowIndex was set to -1 because there
were not any rows in the datagridview when the form loaded and because this
was in a CellValueChanged event that one line was executed. I bypassed this
problem by adding an if statement and checking if the number of rows were <=
0 then exit sub. Would that be an ok workaround?
Thanks,
Tony K
"Cor Ligthert[MVP]" <no************@planet.nlwrote in message
news:3E**********************************@microsof t.com...
Tony,
Be aware that change events normaly are as well called when controls are
initializing, I would put a check around it to see if the index has a
value (probably it is -1 when initialing however I would look at this if I
was you in the debugger).
Cor
"Tony K" <no************@kingprogramming.comschreef in bericht
news:08**********************************@microsof t.com...
>When calling my form from within my MDI, I receive this error message.
InvalidOperationException was unhandled An error occurred creating the form. See Exception.InnerException for details. The error is: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
This error has to do with one line in particular. Me.Inventory_TransactionsDataGridView.Rows(e.RowI ndex).Cells(0).Value = Today()
If I rem this line out, the form loads. What I want to do is when a cell in my DataGridView is changed, insert the date into the 1st column of my DGV. Here are the first several lines of code:
Private Sub Inventory_TransactionsDataGridView_CellValueChange d(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles Inventory_TransactionsDataGridView.CellValueChang ed If e.ColumnIndex = 1 Then 'when the part# combo box is changed (2nd column) Dim cnnProd As New OleDbConnection(My.Settings.Inventory_management_ databaseConnectionString) 'connection used from app settings Dim cmmProd As OleDbCommand Dim strSQL As String 'sql statement Dim description As String Dim drdProd As OleDbDataReader Dim prodID As String Dim unitPrice As Decimal
Me.Inventory_TransactionsDataGridView.Rows(e.RowI ndex).Cells(0).Value = Today()
The last line is the problem line. In the DataGrid I have default cell style set as DataGridViewCellStyle { Format=d }
What can I do to correct this exception problem that I am receiving?
Thanks, Tony K
Tony,
Very well, you can as well use a switch or add the handler after
initializing, however this one is simple enough,
Cor
"Tony K" <no************@kingprogramming.comschreef in bericht
news:28**********************************@microsof t.com...
Yes, that was exactly the problem. e.RowIndex was set to -1 because there
were not any rows in the datagridview when the form loaded and because
this was in a CellValueChanged event that one line was executed. I
bypassed this problem by adding an if statement and checking if the number
of rows were <= 0 then exit sub. Would that be an ok workaround?
Thanks,
Tony K
"Cor Ligthert[MVP]" <no************@planet.nlwrote in message
news:3E**********************************@microsof t.com...
>Tony,
Be aware that change events normaly are as well called when controls are initializing, I would put a check around it to see if the index has a value (probably it is -1 when initialing however I would look at this if I was you in the debugger).
Cor
"Tony K" <no************@kingprogramming.comschreef in bericht news:08**********************************@microso ft.com...
>>When calling my form from within my MDI, I receive this error message.
InvalidOperationException was unhandled An error occurred creating the form. See Exception.InnerException for details. The error is: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
This error has to do with one line in particular. Me.Inventory_TransactionsDataGridView.Rows(e.Row Index).Cells(0).Value = Today()
If I rem this line out, the form loads. What I want to do is when a cell in my DataGridView is changed, insert the date into the 1st column of my DGV. Here are the first several lines of code:
Private Sub Inventory_TransactionsDataGridView_CellValueChange d(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs ) Handles Inventory_TransactionsDataGridView.CellValueChan ged If e.ColumnIndex = 1 Then 'when the part# combo box is changed (2nd column) Dim cnnProd As New OleDbConnection(My.Settings.Inventory_management _databaseConnectionString) 'connection used from app settings Dim cmmProd As OleDbCommand Dim strSQL As String 'sql statement Dim description As String Dim drdProd As OleDbDataReader Dim prodID As String Dim unitPrice As Decimal
Me.Inventory_TransactionsDataGridView.Rows(e.Row Index).Cells(0).Value = Today()
The last line is the problem line. In the DataGrid I have default cell style set as DataGridViewCellStyle { Format=d }
What can I do to correct this exception problem that I am receiving?
Thanks, Tony K
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: TheSteph |
last post by:
Using : Windows 2000 Pro SP4 / VS.NET 2005 / .NET 2.0 / C# - All updates
done.
I have several bugs when I use the DataGridView : When scrolling (or after
scrolling) the grid have these...
|
by: Michael A. Covington |
last post by:
Any thoughts about how best to implement "undo most recent deletion" in a
DataGridView in which the user is allowed to delete rows (but not edit their
contents)?
Is it as simple as stashing a...
|
by: George |
last post by:
Hi,
I have been encountering a refresh problem with DataGridView, which is bound
to a DataTable.
When I make updates (Add, Delete, update) to the DataGridView, everything
flow nicely to...
|
by: joey.powell |
last post by:
I have a Windows Forms application where I need to be able to drag and
then drop onto a datagridview control. I already have the code
necessary to make the drag part work. I am having problems,...
|
by: Mike |
last post by:
Hey everyone...
I've got three problems with a custom DataGridView column I've built
following the "How To: Host Controls in Windows Forms DataGridView
Cells" article. The base editing control...
|
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...
|
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...
|
by: Tony K |
last post by:
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...
|
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,...
|
by: Avedo |
last post by:
Hello!
I have a form application with a DataGridView, and an Save/Delete and Cancel button. When the application is opened, it is supplied an XML file that may or may not exist, and display the...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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...
|
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,...
|
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...
|
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...
|
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...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |