Skip to main content

Hit Information

  • 3 minutes to read

Sometimes in applications you may need to identify which element is located at specific coordinates. For instance, you may need to determine which part of a VGridControl control has been clicked or determine if dropping is allowed to a particular control’s area when performing drag and drop operations.

For the purposes described above, use the grid control’s VGridControlBase.CalcHitInfo method. It accepts a point in grid client coordinates as a parameter and returns a newly created VGridHitInfo object containing information on the grid’s corresponding element. Note that you can also pass a point located outside the grid control. The coordinates should also be measured from the grid control’s top left corner.

The returned VGridHitInfo object exposes information about the point passed via a number of its properties. Use the VGridHitInfo.BandIndex, VGridHitInfo.CellIndex and VGridHitInfo.RecordIndex properties to get the index of a band, cell or record which the specified point belongs to. If a row is at the point specified, you can determine which one it is by the VGridHitInfo.Row property. The VGridHitInfo.HitInfoType property can be used to get the type of an element residing under the test point. This property returns one of the VGridHitInfo enumeration values.

The following example demonstrates how to process information provided by the VGridHitInfo object. It handles the grid’s MouseMove event and displays information about a grid element under the mouse cursor. This example assumes that the form contains the VGridControl and ListBox controls.

private void vGridControl1_MouseMove(object sender, MouseEventArgs e) {
    VGridControl vGrid = sender as VGridControl;
    Point pt = new Point(e.X, e.Y);

    // obtaining information about a point at the specified coordinates
    VGridHitInfo hitInfo = vGrid.CalcHitInfo(pt);
    listBox1.Items.Clear();

    // displaying specific characteristics defined a point under the mouse cursor
    listBox1.Items.Add("BandIndex:   " + hitInfo.BandIndex);
    listBox1.Items.Add("CellIndex:   " + hitInfo.CellIndex);
    listBox1.Items.Add("PtMouse:     " + hitInfo.PtMouse);
    listBox1.Items.Add("RecordIndex: " + hitInfo.RecordIndex);
    listBox1.Items.Add("HitInfoType: " + hitInfo.HitInfoType);
    if (hitInfo.Row == null) return;

    // obtaining the caption of a row containing the test point
    string rowCaption = "";
    if (hitInfo.CellIndex != -1) 
        rowCaption = hitInfo.Row.GetRowProperties(hitInfo.CellIndex).Caption;
    else 
        for (int i=0; i < hitInfo.Row.RowPropertiesCount; i++)
            rowCaption += hitInfo.Row.GetRowProperties(i).Caption + " ";

    // displaying the row's name and caption in the listBox
    listBox1.Items.Add("RowName:     " + hitInfo.Row.Name);
    listBox1.Items.Add("RowCaption:  " + rowCaption);
}

The image below illustrates the sample application. Note that the multiple records view layout is applied to the grid control in this example (the grid’s VGridControl.LayoutStyle property is set to LayoutViewStyle.MultiRecordView). In this layout the control is considered to have a single band. So the VGridHitInfo.BandIndex property always returns 0.

HitInfo_Using