Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datagridview cell balloon tip

Status
Not open for further replies.
Yes, but you can't just set the ToolTipText property of the cell as you'll get a standard tool tip.

You need to add a ToolTip control to the form, and set the IsBalloon property to True. Set the ShowCellToolTip property of the DataGridView to False. In the CellMouseMove handler of the DataGridView add the following:
Code:
If e.RowIndex >= 0 AndAlso e.ColumnIndex >= 0 AndAlso dgv(e.ColumnIndex, e.RowIndex).ToolTipText <> "" Then

    Dim r As Rectangle = dgv.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false)

    Dim pt As Point = new Point(r.Location.X + (r.Width / 2), r.Location.Y + r.Height)

    tt.Show(dgv(e.ColumnIndex, e.RowIndex).ToolTipText, dgv, pt, 10000)

End If
This fixes the balloon at the mid point of the bottom of the cell, wherever the pointer is within the cell. Obviously you can adjust the duration to suit your requirements.

In the CellMouseLeave event, put the following:
Code:
tt.Hide(dgv)
Whenever a cell has a ToolTipText that is not an empty string, the balloon will be shown.
 
Make sure that the ToolTip on... property of the DataGridView is not set, and that the ShowCellToolTip property is set to False.
 
What OS are you using ? The balloon doesn't flash in XP Pro.
 
Code:
Dim clst As New DataGridView
      with clst
         .Add("Content", "Task")
         .Item("Content").AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
         .Item("Content").MinimumWidth = 100
         .EditMode = DataGridViewEditMode.EditOnF2
            .DefaultCellStyle.WrapMode = DataGridViewTriState.True
         .RowHeadersVisible = False
         .GridColor = Color.LightGray
         .AlternatingRowsDefaultCellStyle.BackColor = Color.FromArgb(255, 220, 220, 220)
         .ShowCellToolTips = False
         .Height = main.Height - 25
         .ScrollBars = ScrollBars.Both
       end with
clst.Rows(0).Cells("StartDate").Value = "blah!"

}...the bane of my life!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top