We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to get absolute row,col index under mouse point

Thread ID:





21362 Nov 8,2004 06:10 PM UTC Nov 8,2004 09:23 PM UTC WinForms 3
Tags: GridControl
Keith Steinbeck
Asked On November 8, 2004 06:10 PM UTC

How can I get the absolute row,col index of a grid cell under the mouse? The Grid.CellClicked event gives the "proper" absolute coords, but if you are using Point pt = m_Grid.PointToClient(Cursor.Position); int row, col; m_Grid.ViewLayout.PointToClientRowCol(pt,out row, out col, false, GridCellSizeKind.ActualSize); you get coords of the VISIBLE grid. This works fine if the whole grid fits on the screen, but if not things don''t work quite so well; for example if you are trying to map the coords of the cell to an underlying data structure. So the question becomes: How can I get the absolute cell coords inside a non-MouseEvent-based method or handler, like ContextMenu.Popup?

Administrator [Syncfusion]
Replied On November 8, 2004 06:29 PM UTC

Try using grid.PointToRowCol(pt, out row, out col, -1); // where pt is in the grid coordinate system

Keith Steinbeck
Replied On November 8, 2004 08:17 PM UTC

Great! That seems to do what I need. I''m curious though; the docs for that function state: Points that below the last visible row or right of the last column will be adjusted as defined in the fixOutOfRange parameter. Use -1 if Empty should be returned. The return type is bool, and I don''t think there is a Boolean.Empty. Is this an error in the docs, or am I misunderstanding how this applies? >Try using > >grid.PointToRowCol(pt, out row, out col, -1); // where pt is in the grid coordinate system >

Administrator [Syncfusion]
Replied On November 8, 2004 09:23 PM UTC

It is the row and col returned values that are influenced by the fixOutOfRange value. A zero returns a ''closest'' existing row/col. A non-zero value will return -1''s for both values.


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon