Spread Windows Forms 12.0 Product Documentation
GetCellFromPixel(Int32,Int32,Int32,Int32) Method
Example 


FarPoint.Win.Spread Assembly > FarPoint.Win.Spread Namespace > SpreadView Class > GetCellFromPixel Method : GetCellFromPixel(Int32,Int32,Int32,Int32) Method
Row index in the viewport
Column index in the viewport
X-coordinate (in pixels) of the pointer location
Y-coordinate (in pixels) of the pointer location
Gets the row and column indexes of the cell at the specified pointer location in the view.
Syntax
'Declaration
 
Public Overloads Function GetCellFromPixel( _
   ByVal rowViewportIndex As Integer, _
   ByVal columnViewportIndex As Integer, _
   ByVal x As Integer, _
   ByVal y As Integer _
) As CellRange
'Usage
 
Dim instance As SpreadView
Dim rowViewportIndex As Integer
Dim columnViewportIndex As Integer
Dim x As Integer
Dim y As Integer
Dim value As CellRange
 
value = instance.GetCellFromPixel(rowViewportIndex, columnViewportIndex, x, y)
public CellRange GetCellFromPixel( 
   int rowViewportIndex,
   int columnViewportIndex,
   int x,
   int y
)

Parameters

rowViewportIndex
Row index in the viewport
columnViewportIndex
Column index in the viewport
x
X-coordinate (in pixels) of the pointer location
y
Y-coordinate (in pixels) of the pointer location

Return Value

CellRange object containing the row and column indexes (in a ) for the cell located at the specified pointer location, or (-1,-1,-1,-1) if no cell is located at the specified location
Remarks

This method returns a CellRange object that consists of row and column coordinates and row and column counts. If a cell exists at the pixel location, then the method returns CellRange(row, column, 1, 1) where row, column are the row index and column index of the cell. If a cell does not exist at the pixel location then the method returns CellRange(-1,-1,-1,-1).

Use the x and y parameters to specify the location (pixel) on the display and use the rowviewportindex and columnviewportindex parameters to specify a particular viewport.

This method only returns cell information for pixel locations in the data area of the sheet, and not for headers or sheet corner or other parts of the Spread component. For cells in the column headers and row headers, use the GetColumnHeaderCellFromPixel and GetRowHeaderCellFromPixel methods.

Example
private void fpSpread1MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) 
{
    FarPoint.Win.Spread.SpreadView sv = new FarPoint.Win.Spread.SpreadView(fpSpread1);
    sv = fpSpread1.GetRootWorkbook();
    FarPoint.Win.Spread.Model.CellRange cr;
    cr = sv.GetCellFromPixel(0, 1, e.X, e.Y);
    textBox1.Text = "You are in cell " + cr.Row.ToString() + " - " + cr.Column.ToString();
}
Private Sub FpSpread1MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles FpSpread1.MouseDown
    Dim sv As New FarPoint.Win.Spread.SpreadView(FpSpread1)
    sv = FpSpread1.GetRootWorkbook()
    Dim cr As FarPoint.Win.Spread.Model.CellRange
    cr = sv.GetCellFromPixel(0, 1, e.X, e.Y)
    TextBox1.Text = "You are in cell " & cr.Row.ToString() & " - " & cr.Column.ToString()
End Sub
See Also

Reference

SpreadView Class
SpreadView Members
Overload List

User-Task Documentation

Customizing Interaction in Cells