Oh, you wanted it to be efficient. :)
I was trying to use teh CellTipText property that was added for 1.6. To do so, and be able to work with virtua grids (including GridDataBoundGrid), then the CellTipText would have to be provided dynamically either in Model.QueryCellInfo or PrepareViewStyleInfo.
And yes, you might want to dispose of the Griphics object though it being cretaed on the frame like that may not really require it as it si immediately out of scope and should be processed on the next GC. I just don't know.
Anyway, you can also do it using the standard Windows Forms Tooltip in a dynamic way so it works withvirtual grids without having to greate graphics objects in PrepareViewStyleInfo or QueryCellInfo. Instead, you have to create one each time you enter a new cell. I think this is about teh least you can get away with as you do have to get the string length as some point. And I think trying to store and manage string legths (instead of generating them as you need them) would be a major undertaking, especially for virtual grids.
Here is code that uses a tooltip to dynamically display long text in a cell.
private ToolTip toolTip1;
private int hooverRow = -1;
private int hooverCol = -1;
private void Form1_Load(object sender, System.EventArgs e)
{
this.toolTip1 = new System.Windows.Forms.ToolTip();
toolTip1.InitialDelay = 500; //half a second delay
toolTip1.ReshowDelay = 0;
}
private void gridControl1_MouseMove(object sender, System.Windows.Forms.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
Graphics g = CreateGraphics();
GridStyleInfo style = this.gridControl1[row, col];
if( this.gridControl1.ColWidths[col] - style.TextMargins.Left - style.TextMargins.Right
< g.MeasureString(style.Text, style.GdipFont).Width )
{
this.toolTip1.SetToolTip(this.gridControl1, style.Text);
this.toolTip1.Active = true; //make it active so it can show
}
g.Dispose();
}
}