Solved

Cannot code the CellValueChanged Event?

Posted on 2014-10-07
17
192 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
Comment Utility
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
Comment Utility
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
Comment Utility
Sorry, here is a screenshot.
Screenshot.jpg
0
 
LVL 62

Expert Comment

by:Fernando Soto
Comment Utility
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

Expert Comment

by:Jacques Bourgeois (James Burger)
Comment Utility
What do you mean exactly by "Cannot code the CellValueChanged Event?"

Simply select it in the DropDown ???
0
 

Author Comment

by:BlakeMcKenna
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 250 total points
Comment Utility
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
Comment Utility
Hi BlakeMcKenna;

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

Author Comment

by:BlakeMcKenna
Comment Utility
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
Comment Utility
What exception are you getting and inner exception ?
0
 
LVL 40

Expert Comment

by:Jacques Bourgeois (James Burger)
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks for your help guys!
0
 

Author Comment

by:BlakeMcKenna
Comment Utility
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
Comment Utility
Not a problem, glad to help.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

772 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

11 Experts available now in Live!

Get 1:1 Help Now