Returns the cell position for a set of coordinates.
[Visual Basic]
Public Function CellContaining( _
ByVal x As Integer, _
ByVal y As Integer, _
ByRef row As Integer, _
ByRef col As Integer _
) As Boolean
[C#]
public bool CellContaining(
int x,
int y,
out int row,
out int col
);
[Delphi]
public function CellContaining(
x: Int32;
y: Int32;
out row: Int32;
out col: Int32
): Boolean;
Parameters
x
The x-coordinate.
y
The y-coordinate.
row
The row under the coordinate pair.
col
The column index under the coordinate pair.
Return Value
A value indicating whether a data cell is beneath the specified coordinate pair.
Remarks
The CellContaining method combines the ColContaining and RowContaining methods into one call. If the coordinate pair specified by x and y points to a data cell, this method returns True, and the rowindex and colindex arguments receive zero-based indexes that identify the cell.
This method is useful when working with mouse and drag events when trying to determine where the user clicked or dropped another control in terms of a grid cell.
If the specified coordinate is outside of the grid's data area, this method returns False. Use the PointAt method to determine what kind of grid element, if any, is beneath the specified coordinate.
Example
The following code uses the CellContaining method to save the starting point of the drag operation:
Dim row, col As Integer
Me._ptStartDrag = Point.Empty
Me._dragRow = - 1
If Me.C1TrueDBGrid1.CellContaining(e.X, e.Y, row, col) Then
' Save the starting point of the drag operation.
Me._ptStartDrag = New Point(e.X, e.Y)
Me._dragRow = row
End If
· C#
int row, col;
this._ptStartDrag = Point.Empty;
this._dragRow = - 1;
if ( this.c1TrueDBGrid1.CellContaining(e.X, e.Y, row, col) )
{
// Save the starting point of the drag operation.
this._ptStartDrag = new Point(e.X, e.Y);
this._dragRow = row;
}
· Delphi
var Row, Col: Integer;
begin
FPtStartDrag := Point.Empty;
FDragRow := -1;
if (Self.C1TrueDBGrid1.CellContaining(e.X, e.Y, row, col)) then
begin
// Save the starting point of the drag operation.
FPtStartDrag := Point.Create(e.X, e.Y);
FDragRow := row;
end;
end;
For the full project, see Tutorial 13 - Implementing Drag-and-Drop in C1TrueDBGrid.
See Also
C1TrueDBGrid Class | C1TrueDBGrid Members | C1.Win.C1TrueDBGrid Namespace
Send comments about this topic to ComponentOne. Copyright © ComponentOne LLC. All rights reserved. |