Click here to Skip to main content
15,914,488 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello everybody,
in my program,i have a grid view that show some selected rows from a table in my database.in my form i have a gridview and two button.deletebutton and modifybutton.when i select a row in my gridview and then click delete button , iwant the program to delete that selected row and apply it to its source in my data base.but an error occure while debugging it.here is my code:
VB
Private Sub ButtonX4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonX4.Click
        For Each rows As DataGridViewRow In DataGridView2.SelectedRows
            DataGridView2.Rows.Remove(rows)
        Next
    End Sub

and the error that is occured is:
Unable to cast object of type 'System.Windows.Forms.MouseEventArgs' to type 'System.Windows.Forms.DataGridViewCellEventArgs'.
please help me.
does this code apply the changes to database?
Thanks in Advanced,
Posted
Updated 10-Jun-11 3:31am
v2
Comments
Wayne Gaylard 10-Jun-11 9:46am    
Where do you get the error. This sounds like you are trying to use a mouse event handler to handle a gridview's event, and that the delegate is the wrong type.
Dave Kreskowiak 10-Jun-11 9:50am    
It's impossible for that error to show up in the code snippet you posted.
nafiseh.s 10-Jun-11 9:55am    
i just select row from gridview and then click delbutton.the error exactly show infront of "Private Sub ButtonX4_Click".why????
nafiseh.s 10-Jun-11 9:56am    
but this error shows up!!!!
nafiseh.s 10-Jun-11 9:59am    
i solve my problem.but ihave another question.this code does not apply the changes to database.how can i apply the changes to database?

1 solution

It sounds like you need a more general overview of how DataGridViews work and how to connect to databases. Try reading some CP articles[^] and research the concepts of data binding[^].

Hope this helps.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900