ToolTip Popup event
We want to use tooltips to show additional information, related to a specific cell in a grid.
In the current tooltip system of DapFor, we have to pre-fill all of this data.
For performance and memory reasons, we would like to wait until the user shows interest in this information by hovering over a cell. Then, in an event handler, we want to collect the related information, format it in a string and set this as the tooltip text.
The .NET ToolTip control has a Popup event, but this does not allow to set the text just before showing it. We would have to make an OwnerDrawn tooltip, fetch the cell the user is hovering over and get the correct data.
If the grid could provide a ToolTipPopup event with the correct Cell in its event arguments, this would make it a lot easier for us.
-
Hello,
There are two methods to display a tooltip:
1. As you said by pre-filling data in the Cell.TooltipMessage property
2. By calling the Grid.Tooltips.ShowTooltip() method.In the second case the grid doesn't keep text data per cell which optimizes memory using. The best location to call this method is in the Grid.CellEnter event handler:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
grid1.CellEnter += grid1_CellEnter;
for(int i = 0; i < 10; ++i)
{
string[] data = new string[10];
for(int j = 0; j < 10; j++)
{
data[j] = "item " + i + "," + j;
}
grid1.Rows.Add(data);
}
}
void grid1_CellEnter(object sender, Dapfor.Net.Ui.GridCellEventArgs e)
{
//Here you can change other parameters of the tooltip like colors, orientation etc...
grid1.Tooltips.ShowTooltip(e.Cell, string.Format("{0}: This is a custom message", e.Cell.Text), TimeSpan.FromSeconds(5));
}
}You can find the full example in attachments
Best regards,
The Dapfor Team
TooltipDemo.zip0
Please sign in to leave a comment.
Comments
1 comment