Articles in this section
Category / Section

How to display tooltip that vary from cell to cell in the WinForms GridControl?

2 mins read

Tooltip

You can use the System.Windows.Forms.Tooltip class to add tips that vary from cell to cell in an Essential Grid and it is performed using a MouseMove event handler. As you move to a different cell, you can turn off the current tip when it is visible and reset it with your new text depending upon the current cell. The following code example illustrates how to achieve this.

C#

//declaring ToolTip
private System.Windows.Forms.ToolTip toolTip1;
private int hooverRow = -1;
private int hooverCol = -1;
private void Form1_Load(object sender, EventArgs e)
{
   //Initialize the tip with desired timing parameters
   this.toolTip1 = new System.Windows.Forms.ToolTip();
   toolTip1.InitialDelay = 500; //Half a second delay
   toolTip1.ReshowDelay = 0;
}

VB

'declaring ToolTip
Private toolTip1 As System.Windows.Forms.ToolTip
Private hooverRow As Integer = -1
Private hooverCol As Integer = -1
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
   'Initialize the tip with desired timing parameters
   Me.toolTip1 = New System.Windows.Forms.ToolTip()
   toolTip1.InitialDelay = 500 'Half a second delay
   toolTip1.ReshowDelay = 0
End Sub

The following code example illustrates turning off/on ToolTip on MouseMove event.

C#

private void gridControl1_MouseMove(object sender, MouseEventArgs e)
{
   int row, col;
   if(this.gridControl1.PointToRowCol(new Point(e.X, e.Y), out row, out col)
&& (col != hooverCol || row != hooverRow))
   {
      hooverCol = col;
      hooverRow = row;
      if(this.toolTip1 != null && this.toolTip1.Active)
        this.toolTip1.Active = false; //Turn it off
      this.toolTip1.SetToolTip(this.gridControl1, string.Format("tooltip: row {0}, column {1}", hooverRow, hooverCol));
      this.toolTip1.Active = true; //Make it active so it can show
   }
}

VB

Private Sub gridControl1_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs)
Dim row, col As Integer
   If Me.gridControl1.PointToRowCol(New Point(e.X, e.Y), row, col) AndAlso (col <> hooverCol OrElse row <> hooverRow) Then
     hooverCol = col
     hooverRow = row
     If Me.toolTip1 IsNot Nothing AndAlso Me.toolTip1.Active Then
       Me.toolTip1.Active = False 'Turn it off
     End If
     Me.toolTip1.SetToolTip(Me.gridControl1, String.Format("tooltip: row {0}, column {1}", hooverRow, hooverCol))
     Me.toolTip1.Active = True 'Make it active so it can show
   End If
End Sub

The following screenshot illustrates the Tooltip in GridControl.

Show the tooltip in GridControl

Figure 1: Tooltip in GridControl.

Sample: http://www.syncfusion.com/downloads/support/directtrac/general/WF-15688_How_do_I_display_tips_that_vary_from_cell_to_cell-551440905.zip

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied