Click here to Skip to main content
15,891,846 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I've a windows Form and what I need is if we click on any ROW in datagriedview and click on delete button in the form, it should have another form open.
For this, I created a ROW_click Event Method, that's fine, but simultaneously I want to check if the delete button is clicked inside this method.

please help me out.

C#
private void dgvRow_Click_delet(object sender, EventArgs e)
       {
           if (btnDelete.c)//my question is on this.
           {
               AdrsdetailShow();
           }

         }

The OP added as an answer:

"Sorry, I am confused.
Here I tell you exactly what needs to be, we should select any row and if we click delete button it'll show another form.
How would it be achieved?"

And then added as another answer:

"thank u for reply. please tell me how to count selectedRows or to use SelectedRows property with an example. help me out"


[edit]OP answers moved to question - OriginalGriff[/edit]
Posted
Updated 13-Jan-11 22:34pm
v5
Comments
Dalek Dave 14-Jan-11 4:34am    
Edited for Grammar, Syntax and Readability.

No, sorry it doesn't work like that.

When the user clicks on any row in the DataGridView, he can't simultaneously click on a delete button in your form: he only has one mouse pointer!

What are you actually trying to achieve, because I think your implemenation is getting a little confused!


"sorry, i confused. here i tell u exactly what needs to be, we should select any row and if we click delete button it'll show another form. how would it achieved. reply me"

Please do not use the "Add answer" button - if you use "Add Comment" then I get an email, rather than my looking back at some point in the future. You generally get a quicker response that way!

As Espen Harlinn says, The DGV has a SelectedRows property which you can iterate through in your Button click event:
foreach (DataGridViewRow row in myGrid.SelectedRows)
   {
   ...
   }
You can then assemble whatever information you want and show your second form.
 
Share this answer
 
v2
Comments
Espen Harlinn 14-Jan-11 3:08am    
5+ good point, clear explaination :)
Аslam Iqbal 14-Jan-11 3:25am    
yeah
JF2015 14-Jan-11 3:27am    
Great answer. 5+
Dalek Dave 14-Jan-11 4:34am    
Good answer, well explained.
As OriginalGriff said your design seems a bit unorthodox. The DataGridView has a SelectedRows property allowing you to determine which rows are selected. There is also the SelectionMode property that allows you to decide how selection works for your DataGridView.

I think you should use this mechanism to determine the selected rows in your button click event handler. You can then show you other form.

Regards
Espen Harlinn
 
Share this answer
 
Comments
OriginalGriff 14-Jan-11 3:29am    
+5 - thanks for the SelectedRows, I should have mentioned that originally!
Espen Harlinn 14-Jan-11 3:32am    
Thanks OriginalGriff
Dalek Dave 14-Jan-11 4:35am    
Good Call.
Espen Harlinn 14-Jan-11 4:41am    
Thanks Dalek!

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