Solved

Cannot code the CellValueChanged Event?

Posted on 2014-10-07
17
200 Views
Last Modified: 2014-10-07
What DataGridView Event should be used in order to check the value of an invisible cell?
0
Comment
Question by:BlakeMcKenna
  • 8
  • 6
  • 3
17 Comments
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 40365993
I am assuming that this is a Windows form application because you are using a DataGridView. You should be able to create it. How are you attempting to create it and what do you mean by it will not come up in code behind?
0
 

Author Comment

by:BlakeMcKenna
ID: 40366013
Fernando,

You are correct, it is a Windows App. I'm basically just referencing the DGV from the Control Dropdown list in the designer and then click the desired event from the Events Dropdown list.
0
 

Author Comment

by:BlakeMcKenna
ID: 40366015
Sorry, here is a screenshot.
Screenshot.jpg
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 40366067
Hi BlakeMcKenna;

I was more interested in the signiture of the CellValueChanged event method you used. See if your event method matches this one. Note that in the below event it is using DataGridView1 as the instance name please change the two places where that occurs to use it in your code.

Private Sub DataGridView1_CellValueChanged(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellValueChanged

End Sub

Open in new window

0
 
LVL 40
ID: 40366123
What do you mean exactly by "Cannot code the CellValueChanged Event?"

Simply select it in the DropDown ???
0
 

Author Comment

by:BlakeMcKenna
ID: 40366173
That's my problem...I can't create the CellValueChanged Event by simply selecting the dgv name and then selecting the CellValueChanged Event. When I do that...the cursor is placed within an existing Event for that dgv. The application isn't running either. I'm in design view within the code-behind.
0
 

Author Comment

by:BlakeMcKenna
ID: 40366182
Fernando,

I was able to create it manually by typing in the event. But now I get the following error (see attachment).
Screenshot.jpg
0
 
LVL 62

Assisted Solution

by:Fernando Soto
Fernando Soto earned 250 total points
ID: 40366195
What happens when you place that method in your code and write the code in it to handle the event?

Also you may want to do a Build -> Clean Solution from Visual Studio main menu. compile it and see if the event shows up in the drop down list.

I have seen at times when an event does not show up in the drop down, but when you just add the event by hand it works fine.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 250 total points
ID: 40366203
IsDBNull works with data that comes from a database, either in a DataTable or a DataReader. You cannot use it for .NET objects. For these, you use the notion of Nothing instead:

If row.Cells(12).Value IsNot Nothing then
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 40366212
Hi BlakeMcKenna;

This is a different issue now look at James post above.
0
 

Author Comment

by:BlakeMcKenna
ID: 40366279
Guys,

I actually have the Event firing now...just not sure why the code isn't working even though it gets executed.

Although I still don't know why I am unable to select the Event from the DropDown List even though the Event is listed.

    Private Sub dgvSTEquipmentAvail_CellValueChanged(sender As Object, e As DataGridViewCellEventArgs) Handles dgvSTEquipmentAvail.CellValueChanged
        Try
            If Not blnIsLoaded Then
                If e.RowIndex >= 0 Then
                    Select Case e.ColumnIndex
                        Case 12
                            If Not IsDBNull(dgvSTEquipmentAvail.Rows(e.RowIndex).Cells(12).Value) Then
                                If dgvSTEquipmentAvail.Rows(e.RowIndex).Cells(12).Value > 0 Then
                                    If dgvSTEquipmentAvail.Rows(e.RowIndex).Cells(12).Value = gWorkStation_ID Then
                                        Dim cboSelected As DataGridViewCheckBoxCell = dgvSTEquipmentAvail.Rows(e.RowIndex).Cells(0)

                                        cboSelected.Value = True
                                        dgvSTEquipmentAvail.Rows(e.RowIndex).Cells(0).Selected = True
                                    End If
                                End If
                            End If
                    End Select
                End If
            End If

        Catch ex As Exception
            EH.ErrorMessage = "frmCalibration_3/dgvSTEquipmentAvail_CellValueChanged() - " & ex.Message & "...Contact Engineering!" & "~E"
        End Try
    End Sub

Open in new window

0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 40366294
What exception are you getting and inner exception ?
0
 
LVL 40
ID: 40366335
Usually, when you can't get the event procedure from the drop down, it's because the application is running. In such a situation, the dropdown can be used to navigate in already written code, but it cannot generate new events. They should display the uncoded events in grey when the code is running.
0
 

Author Comment

by:BlakeMcKenna
ID: 40366340
I got it working. Here is my code below. I actually went back to the CellFormatting Event...and Fernando, I basically restarted Visual Studio and was able to create the CellValueChanged Event in the normal fashion!
0
 

Author Closing Comment

by:BlakeMcKenna
ID: 40366346
Thanks for your help guys!
0
 

Author Comment

by:BlakeMcKenna
ID: 40366369
James,

Fortunately that didn't take to much to figure out. That's usually the first thing I check and I usually find out when I try to make changes in the code and can't even hit the "Enter" key.

Thanks again!
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 40366373
Not a problem, glad to help.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help with error message for ReportViewer in VS2015 4 46
Copy/Clone an object. 9 30
Getfiles in vb.net 28 44
Get size of each directory on each mapped drive 5 24
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
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…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

863 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now