Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 226
  • Last Modified:

Cannot code the CellValueChanged Event?

What DataGridView Event should be used in order to check the value of an invisible cell?
0
BlakeMcKenna
Asked:
BlakeMcKenna
  • 8
  • 6
  • 3
2 Solutions
 
Fernando SotoCommented:
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
 
BlakeMcKennaAuthor Commented:
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
 
BlakeMcKennaAuthor Commented:
Sorry, here is a screenshot.
Screenshot.jpg
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Fernando SotoCommented:
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
 
Jacques Bourgeois (James Burger)Commented:
What do you mean exactly by "Cannot code the CellValueChanged Event?"

Simply select it in the DropDown ???
0
 
BlakeMcKennaAuthor Commented:
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
 
BlakeMcKennaAuthor Commented:
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
 
Fernando SotoCommented:
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
 
Jacques Bourgeois (James Burger)Commented:
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
 
Fernando SotoCommented:
Hi BlakeMcKenna;

This is a different issue now look at James post above.
0
 
BlakeMcKennaAuthor Commented:
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
 
Fernando SotoCommented:
What exception are you getting and inner exception ?
0
 
Jacques Bourgeois (James Burger)Commented:
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
 
BlakeMcKennaAuthor Commented:
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
 
BlakeMcKennaAuthor Commented:
Thanks for your help guys!
0
 
BlakeMcKennaAuthor Commented:
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
 
Fernando SotoCommented:
Not a problem, glad to help.
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

  • 8
  • 6
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now