Admin Production ni-theme
Current Publication

GetTableCellFromPoint

LabWindows/CVI

GetTableCellFromPoint

int GetTableCellFromPoint (int panelHandle, int controlID, Point panelCoordinates, Point *cell);

Purpose

Converts panel coordinates into a table control cell.

GetTableCellFromPoint returns a cell containing the indices {0, 0} if the specified coordinates lie outside the cell grid.

Supported Controls

You can use GetTableCellFromPoint with table controls.

Parameters

Input
Name Type Description
panelHandle int Specifier for a particular panel that is currently in memory. You can obtain this handle from functions such as LoadPanel and NewPanel.
controlID int The defined constant, located in the .uir header file, that you assigned to the control in the User Interface Editor, or the ID returned by functions such as NewCtrl and DuplicateCtrl.
panelCoordinates Point A Point structure specifying the panel coordinates.

The Point structure is defined as follows:

typedef struct
   {
   int x;
   int y;
   } Point;


The values in the Point structure are in terms of pixel coordinates. The origin (0,0) is the upper left corner of the panel.

You can create a Point without having to declare a variable by using the following function:

Point MakePoint (int x, int y);

Example Code

GetTableCellFromPoint (panelHandle, controlID, MakePoint (20, 30), &cell);

This function can return a cell that is scrolled out of view. If you want to restrict the specified coordinates to the visible portion of the table, you must use the following code:

GetCtrlAttribute (panelHandle, controlID, ATTR_GRID_AREA_TOP, &top);
GetCtrlAttribute (panelHandle, controlID, ATTR_GRID_AREA_LEFT, &left);
GetCtrlAttribute (panelHandle, controlID, ATTR_GRID_AREA_WIDTH, &width);
GetCtrlAttribute (panelHandle, controlID, ATTR_GRID_AREA_HEIGHT, &height);
cell.x = 0;
cell.y = 0;

if (point.x >= left && point.x < left + width)
  if (point.y >= top && point.y < top + height)
    GetTableCellFromPoint (panelHandle, controlID, point, &cell);

Output
Name Type Description
cell Point A Point structure indicating the row and column of the cell corresponding to the specified value.

The Point structure is defined as follows:

typedef struct
   {
   int x;
   int y;
   } Point;


The function writes the one-based column index of the corresponding cell into the x field of the structure, and the one-based row index of the corresponding cell into the y field of the structure.

If the specified coordinates lie outside the cell grid, the function returns a cell containing the indices {0, 0}.

This function can return a cell that is scrolled out of view. If you want to restrict the specified coordinates to the visible portion of the table, you must use the following code:

GetCtrlAttribute (panelHandle, controlID, ATTR_GRID_AREA_TOP, &top);
GetCtrlAttribute (panelHandle, controlID, ATTR_GRID_AREA_LEFT, &left);
GetCtrlAttribute (panelHandle, controlID, ATTR_GRID_AREA_WIDTH, &width);
GetCtrlAttribute (panelHandle, controlID, ATTR_GRID_AREA_HEIGHT, &height);

cell.x = 0;
cell.y = 0;

if (point.x >= left && point.x < left + width)
  if (point.y >= top && point.y < top + height)
   GetTableCellFromPoint (panelHandle, controlID, point, &cell);

Return Value

Name Type Description
status int Return value indicating whether the function was successful. A negative number indicates that an error occurred.

Additional Information

Library: User Interface Library

Include file: userint.h

LabWindows/CVI compatibility: LabWindows/CVI 5.5 and later

Examples

Refer to the following examples that use the GetTableCellFromPoint function:

  • userint\gridview.cws

    Open example
  • userint\custctrl\toolbar\tooldemo.cws

    Open example