Click here to Skip to main content
15,884,425 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I created some datagridview and their ContextMenuStrip by code.
There are many options in ContextMenuStrip.
I need the following:
1- Identify the datagridview I clicked on when the ContextMenuStrip item is selected.
2- or return the row information after selecting ContextMenuStrip item.
Posted
Updated 18-Dec-10 23:30pm
v2

To help with your first problem Getting the control that called a context menu[^]

I am not sure that I understand your second part. 'return' to where? perhaps you could expand that a little to make your question clearer.
 
Share this answer
 
v2
tank you for your answer
and i main in the seconed part
after i select an item from the ContextMenuStrip i need to determaine which row or select the row that clicked on
 
Share this answer
 
thanx for all
i found the solution
part 1:
use SourceControl proprity for ContextMenuStrip which return the last control of the ContextMenuStrip

part2:
determin the rowindex using mousedown event on the datagridview
 
Share this answer
 
For your second part DataGridView has a CurrentRow[^] property. You'll never guess what it returns. :)

I am not sure whether it will solve your problem as, without checking, I do not know if it gets set for a right click. Still check it out, it might do the trick.
 
Share this answer
 
for Your second Question you can do this step

Me.Datagrid.CurrentRow.Cells.Item(0).Value.ToString

This code shows you which row selected and you can put 0 to length of your columns to manage which of column you want to return data

and you can use this code for Just Know About which of rows was Selected
Me.Datagrid.CurrentRow :)
 
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