This is a migrated thread and some comments may be shown as answers.

Tooltip for TextBoxes inside RadGridView

1 Answer 190 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Tamás
Top achievements
Rank 1
Tamás asked on 05 Sep 2008, 12:36 PM
Hi,

I would like to add tooltips to textboxes when I click in a cell inside RadGridView. I subscribed to the RadGridView.CellFormatting event and did the following, but it doesn't seem to work:

private void rgvEditor_CellFormatting(object sender, CellFormattingEventArgs e)
        {
            if (e.CellElement.ChildrenHierarchy.Count > 0)
            {
                foreach (RadElement element in e.CellElement.ChildrenHierarchy)
                {
                    if (element is RadTextBoxItem)
                    {
                        RadTextBoxItem textBoxItem = (RadTextBoxItem)element;
                        textBoxItem.TextAlign = HorizontalAlignment.Center;
                        textBoxItem.AutoToolTip = true;
                        textBoxItem.ToolTipText = "hello";
                    }
                }
            }

Can you help me?

Thanks,
Tamás

1 Answer, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 08 Sep 2008, 04:06 PM
Hi Tamás,

Thank you for this question.

Microsoft TextBox control used in RadGridView does not support tool tips without an instance of the ToolTip object. Therefore, we should first manually create the ToolTip and then assign it to the textbox. The EditorRequired event is more suitable for our custom implementation than the CellFormatting event. This event is fired every time when an editor is required and needs to be initialized. Consider the sample code below:

ToolTip tip = new ToolTip();  
Point mousePos;  
 
void radGridView1_EditorRequired(object sender, EditorRequiredEventArgs e)  
{  
    RadTextBoxEditor editor = e.Editor as RadTextBoxEditor;  
    if (editor != null)  
    {  
        editor.TextAlign = HorizontalAlignment.Center;  
        editor.AutoToolTip = true;  
        TextBox textBox = (TextBox)editor.HostedControl;  
        textBox.MouseMove += new MouseEventHandler(textBox_MouseMove);  
        textBox.MouseLeave += new EventHandler(textBox_MouseLeave);  
    }  
}  
 
void textBox_MouseMove(object sender, MouseEventArgs e)  
{  
    if (mousePos != e.Location)  
    {  
        TextBox textBox = (TextBox)((RadTextBoxEditor)this.radGridView1.ActiveEditor).HostedControl;  
        tip.Show("hello", textBox, new Point(e.Location.X + 7, e.Location.Y + 7));  
        mousePos = e.Location;  
    }  
}  
 
void textBox_MouseLeave(object sender, EventArgs e)  
{  
    TextBox textBox = (TextBox)((RadTextBoxEditor)this.radGridView1.ActiveEditor).HostedControl;  
    Rectangle bounds = new Rectangle(textBox.PointToScreen(Point.Empty), textBox.Size);  
    if (!bounds.Contains(Control.MousePosition))  
    {  
        tip.Hide(textBox);  
    }  

I hope this helps. Do not hesitate to write me if you need further assistance.

Kind regards,
Jack
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
GridView
Asked by
Tamás
Top achievements
Rank 1
Answers by
Jack
Telerik team
Share this question
or