Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How To Get A Row From Datagrid?

Status
Not open for further replies.

litton1

Technical User
Apr 21, 2005
584
GB
Please could someone tell me how to get the current row that has been clicked in a datagrid? I am sure there is a simple solution but just cannot seem to find how to do it

Age is a consequence of experience
 
Solved! Thx MSDN :)
Code:
int aRow = 0;
			int aCol = 0;
			// Use the HitTest method to get a HitTestInfo object.
			DataGrid.HitTestInfo hi;   
			DataGrid grid = (DataGrid)sender;
			hi=grid.HitTest(e.X, e.Y);
			// Test if the clicked area was a cell.
			//could have been a header
			if (hi.Type == DataGrid.HitTestType.Cell)
			{

				aRow = hi.Row + 1;
				aCol = hi.Column + 1;

Age is a consequence of experience
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top