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

Find Grid Cell by X,Y at MouseDown event

How does one hittest for a cell using X,Y from grid_mousedown event? I thought GridRangeInfo.FromTlhw(y,x,0,0) would do, but, the GridRangeInfo object it returns has X as the Left and Y as the Top, not the actual cell row /column index. I Don't think I can use CellMouseDown event, because I'm trying to find for disabled, read-only cells. Haven't actually tried... however, I'd still be interested in knowing how to find acell based on grid's X,Y coordinates. Thanks Eric

3 Replies

AD Administrator Syncfusion Team August 14, 2003 05:39 PM UTC

Is this what you needed?
Private Sub gridControl1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Sub gridControl1.MouseDown
        If e.Button = MouseButtons.Right Then
       		dim rowIndex, colIndex as Integer
		Me.gridControl1.PointToRowCol(New Point(e.X, e.Y), rowIndex, colIndex)
		Console.WriteLine(rowIndex.ToString() + "  " + colIndex.ToString())
        End If
End Sub

private void gridControl1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
	if(e.Button == MouseButtons.Right)
		int row, col;
		if(this.gridControl1.PointToRowCol(new Point(e.X, e.Y), out row, out col, -1))
			Console.WriteLine(row.ToString() + "  " + col.ToString())

ER ERobishaw August 14, 2003 07:47 PM UTC

Perfect... What is GridRangeInfo.FromTlhw(y,x,...) used for? Eric

AD Administrator Syncfusion Team August 14, 2003 08:17 PM UTC

It is just a static method that takes top, left, height,width and returns a GridRangeInfo object based on these entires. The 'normal' GridRangeInfo.Cells static method takes top, left, bottom, right.

Live Chat Icon For mobile
Up arrow icon