Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to show tooltip of each row of GridView. For which i have written following code on
RowDataBound event of Grid :

C#
DataSet dtset = new DataSet("root");
            dtset.ReadXml(Server.MapPath(@"~\XMLFILE.xml"));
            try
            {
                if (dtset != null & dtset.Tables.Count > 0)
                {
                    for (int colIndex = 0; colIndex < e.Row.Cells.Count; colIndex++)
                    {
                        // Do database lookup
                        //string ttString = "Result of database lookup";
                        // strReturn = strReturn.Replace("[Page]", strPage);
                        DataRow [] dr = dtset.Tables[0].Select("Measure ='"+e.Row.Cells[0].Text.ToUpper()+"'");
                        if(dr!= null && dr.Length >0)
                        {
                              // First approach                         
                              e.Row.Cells[colIndex].Attributes.Add("title", Convert.ToString(dr[0][1]));
                             // Second approach
                            e.Row.ToolTip = Convert.ToString(dr[0][1]);

                        }
                    }
                }
            }



I am reading all tool tips from XML file and assigning them to Row as per their title.

Now my Problem is I have along text to show in tooltip and above code works fine but string is truncated because of length. Length of string is almost 250-300 characters including new line.

Any idea why string is truncated on its own and what can be done to sort it out ?
Posted
Updated 3-Jul-13 1:52am
v2

1 solution

Example using draw: http://msdn.microsoft.com/en-us/library/system.windows.forms.tooltip.draw.aspx[^]

I think essentially that you need to measure the text to display without any truncating and allow wrap (if too long for the screen or tooltip popup).

VB
' Determines the correct size for the button2 ToolTip.
    Private Sub toolTip1_Popup(ByVal sender As System.Object, _
        ByVal e As PopupEventArgs) Handles toolTip1.Popup

        If e.AssociatedControl Is button2 Then

            Dim f As New Font("Tahoma", 9)
            Try
                e.ToolTipSize = TextRenderer.MeasureText( _
                    toolTip1.GetToolTip(e.AssociatedControl), f)
            Finally
                f.Dispose()
            End Try

        End If
    End Sub



I pulled that code from here: http://msdn.microsoft.com/en-us/library/system.windows.forms.tooltip.ownerdraw.aspx[^]
 
Share this answer
 
Comments
deepakdynamite 4-Jul-13 3:23am    
Thanks alot for your efforts but I am working with asp.net i.e Web application whereas this looks like windows application. Right ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900