Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VB 2008  - DatagridView RowLeave event error

Posted on 2009-07-06
30
Medium Priority
?
694 Views
Last Modified: 2012-05-07
Each row of DataGridView has a field, uProjectID that in which Visible = False.  I want to assign a Value to this field during the RowLeave event.  However, the field uProjectID "cannot be found".  This is shown in the error pictured below.

Should the word "Item" in the assignment statement be changed to reflect "column name"?

Why does this error occur and how is this error overcome?

error.JPG
0
Comment
Question by:ljcor
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 16
  • 14
30 Comments
 
LVL 15

Expert Comment

by:JackOfPH
ID: 24790623
Change it to:


EvalItemDatagridView.Item(uProjectID.index, EvalItemsDatagridView.CurrnetRow.index).Value = uItemID

Open in new window

0
 

Author Comment

by:ljcor
ID: 24790930
The design-time compiler does not like:
  EvalItemDatagridView.Item(uProjectID.index,
It says uProjectID is not declared.   It is a field name in the row.
0
 
LVL 15

Expert Comment

by:JackOfPH
ID: 24791005
Is it the columname in the datagridRow?

uProjectID should be the name of the column...
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:ljcor
ID: 24791019
It is the name of the column just as it is spelled here: uProjectID.  It is not visible but that should not matter, I believe.  It is still in the row/s.
0
 

Author Comment

by:ljcor
ID: 24791028
There were a couple of small typo's in your statement but I modified them as I entered the statement.

EvalItemsDataGridView.Item(uProjectID.index, EvalItemsDataGridView.CurrentRow.Index).Value = uItemID
0
 
LVL 15

Expert Comment

by:JackOfPH
ID: 24791054
Is it working now?
0
 

Author Comment

by:ljcor
ID: 24791068
No.  I had made the corrections as I put the statement in initially.  Did not change it since.
0
 
LVL 15

Expert Comment

by:JackOfPH
ID: 24791072
Is the uProjectID is the first column in the grid?
0
 

Author Comment

by:ljcor
ID: 24791079
No, it is the last column.  The last visible column does require data entry by the user.
0
 
LVL 15

Expert Comment

by:JackOfPH
ID: 24791095
what would be the output if you do this?

msgbox(uProjectID.index)
0
 

Author Comment

by:ljcor
ID: 24791099
Just so you know, if I change the reference to uProjectID to the name of one of the interior (visible) fields, the same error shows up.
0
 
LVL 15

Expert Comment

by:JackOfPH
ID: 24791187
is it binded?
0
 

Author Comment

by:ljcor
ID: 24791194
When I put in that Msgbox statement I still get the same error - not declared.

The fields are all bound.

And Jack, I am not feeling well and have to go to bed now.  If you come up with another thought just feel free to post it.  If I wake up later (or even tomorrow) I will get back to it.  It can wait until tomorrow if necessary.  I can work around it until then.
0
 
LVL 15

Expert Comment

by:JackOfPH
ID: 24791200
ok...
0
 
LVL 15

Expert Comment

by:JackOfPH
ID: 24791251
This function will show you all the columns you have in the gridview, from there select the column name that you think is the name of uProjectID, then replace uProjectID in your code to the one you select.


Put this line of code in the last line of your form load event...

RetrieveColumnamesInTheGrid


 
Private Sub RetrieveColumnamesInTheGrid 
 
For ctr As Integer = 0 To DataGridView1.Columns.Count - 1
 
            MsgBox("Column name: " & DataGridView1.Columns(ctr).Name & " ColumnIndex: " & DataGridView1.Columns(ctr).Index)
 
        Next
 
End Sub

Open in new window

0
 

Author Comment

by:ljcor
ID: 24792480
Here is the list generated by your test procedure:

Column Name: DataGridTextBoxColumn2 ColumnIndex: 0
Column Name: DataGridTextBoxColumn3 ColumnIndex: 1
Column Name: DataGridTextBoxColumn4 ColumnIndex: 2
Column Name: DataGridTextBoxColumn5 ColumnIndex: 3
Column Name: DataGridTextBoxColumn6 ColumnIndex: 4
Column Name: DataGridTextBoxColumn7 ColumnIndex: 5
Column Name: DataGridTextBoxColumn8 ColumnIndex: 6
Column Name: DataGridTextBoxColumn9 ColumnIndex: 7
Column Name: DataGridTextBoxColumn1 ColumnIndex: 8

Also is an attached screenshot of the "Edit Columns" properties showing uProjectID


                         
error.JPG
0
 
LVL 15

Expert Comment

by:JackOfPH
ID: 24792544
In your screen shot the uProjectID is not the name of the column it is the text of the column the one that you see in the header.

Name of the column is the one below:

use that value in your code...


error.JPG
0
 

Author Comment

by:ljcor
ID: 24792565
The (Name) is: DataGridViewTextBoxColumn2.  That is a copy of that line.  I didn't type it.
0
 
LVL 15

Expert Comment

by:JackOfPH
ID: 24792579
the code should be like this:
EvalItemsDataGridView.Item(DataGridViewTextBoxColumn2.index, EvalItemsDataGridView.CurrentRow.Index).Value = uItemID
 
 
or 
 
EvalItemsDataGridView.Item("DataGridViewTextBoxColumn2", EvalItemsDataGridView.CurrentRow.Index).Value = uItemID

Open in new window

0
 

Author Comment

by:ljcor
ID: 24792611
I put it in as you show in line1 above. When I ran it I received an error Dialog window saying that uProjectID does not accept nulls.

So I ran it again with a messagbox showing the uItemID.  It is not null.  It shows a value of 100051, just as it should.
0
 

Author Comment

by:ljcor
ID: 24792637
Here is the line as it is being executed:
        EvalItemsDataGridView.Item(DataGridViewTextBoxColumn2.Index, EvalItemsDataGridView.CurrentRow.Index).Value = uItemID
0
 
LVL 15

Expert Comment

by:JackOfPH
ID: 24792640
Did you call any save, before executing your code?

This happens because in your database you set the property of the field AcceptNull to false.
0
 

Author Comment

by:ljcor
ID: 24792669
I don't know what you mean by "call any save."

It is true that I set AcceptNull to false.  Isn't that what it should be?  uProjectID is the unique Key to the record and should never be null, I believe.  Am I thinking wrong here?
0
 
LVL 15

Accepted Solution

by:
JackOfPH earned 2000 total points
ID: 24792685

If this is an Access Database at is the Primary key use the Autonumber datafield instead.

And if it SQL Server Set the Identity Seed to yes.


By Doing this you will automatically incrementing the value and no need for the additional code...

Jack
0
 
LVL 15

Expert Comment

by:JackOfPH
ID: 24792697
It is late in the afternoon here...

I need to go... I will check out this thread tomorrow...

Take care friend...

:)
0
 

Author Comment

by:ljcor
ID: 24792698
This is a Compact SqlServer DB.  I did not want to have the automatic increment at the time I set it up but I don't recall why now.  Probably just a bit of faulty thinking.  

But should that matter to the problem going on here?
0
 

Author Comment

by:ljcor
ID: 24792707
Thanks Jack.  We can take it up then.
0
 

Author Closing Comment

by:ljcor
ID: 31600398
Jack - I did set the Identity seed and made that automatic.  Then it worked just fine without any code at all.  As I am sure you knew.  I thank you for all of your help on this.  I am still left with one similar problem we haven't approached yet but that can be worked on another time.  And where are you located, Singapore?  Hong Kong? or similar?
0
 
LVL 15

Expert Comment

by:JackOfPH
ID: 24799693
I am from the Philippines, Remember?
0
 

Author Comment

by:ljcor
ID: 24799919
Oh yes! The Philippines.  My memory is not always in working order.
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question