Recently I was looking for the Location of a clicked DGV-Cell on the display.
The object cell seems to have a Size property, but obviously no Location.
With WindowsForms you can find the Location if you extract it e.g. with
Rectangle rec = DisplayedDGV.GetCellDisplayRectangle(1, e.RowIndex, true);
Point cellLocation = new Point(rec.Location);
Unfortunately, the Wisej DGVCell seems neither to have a Method similar to GetCellDisplayRectangle(), nor the DisplayRectangle property like the DGV itself.
Could you please suggest a way to find out the location of a clicked cell? [(Left;Top) or (X;Y)]
Thanks a lot,
Hi, many thanks for your proposal.
Actually I was only trying to create a temporary replacement for a Master-Detail (hierarchical) DataGridView.
Though the native Windows Forms control datagridview also doesn’t support Master-Detail views within a single control, CodeProject or c-sharpcorner are offering some not too difficoult samples for it.
As a first try I took a project of Sayed Shanu http://www.c-sharpcorner.com/uploadfile/asmabegam/master-detail-datagridview-in-c-sharp-winform/.
The conversion is quite simple, for the positioning of the detailDGV I took the iteration way as you proposed (even if it’s not exactly an elegant solution).
My only problem is the image column on the left. The images get visible only after the first mouse click.
What’s wrong with them?
It’s relatively easy to add those methods, the only issue is the scroll position. I will log an enhancement for these methods.
As a quick workaround you can iterate the columns and rows and get the location by adding the column.Width and row.Height. WinForms does the same internally. What do you need the cell rect for? If it’s used mostly in clicks, it’s faster to make the widget return the rect with the click event and avoid the iteration.