Solved

Cannot code the CellValueChanged Event?

Posted on 2014-10-07
17
215 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
[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
  • 8
  • 6
  • 3
17 Comments
 
LVL 63

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
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!

 
LVL 63

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 63

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
 
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 63

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 63

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 63

Expert Comment

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

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

738 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