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

Adding ToolTip to RadComboBox Programmatically

5 Answers 615 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Joe
Top achievements
Rank 2
Joe asked on 08 Sep 2011, 05:52 AM
Im attempting to build a combobox and populate it with data. everything works, but I would also like to add tooltips using data from my database. My code is as follows:
radcombo_mns_severity.DataTextField = "SEVERITY";
radcombo_mns_severity.DataValueField = "ID";
radcombo_mns_severity.ToolTip = "DESC";
radcombo_mns_severity.DataSource = from c in quarkdb.MNS_SEVERITies
                                   orderby c.SEVERITY
                                   select new
                                   {
                                       c.SEVERITY,
                                       c.ID,
                                       c.DESC
                                   };
radcombo_mns_severity.DataBind();

Is there away to do this?

5 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 08 Sep 2011, 06:28 AM
Hello Joe,

You can easily achieve this by using RadToolTip inside ItemTemplate. Here is a sample code.

aspx:
<telerik:RadComboBox ID="RadComboBox1" runat="server" EmptyMessage="Select" DataTextField="Name">
     <ItemTemplate>
         <asp:Label runat="server" ID="Label1" Text='<%# Eval("Name")%> '></asp:Label>
         <telerik:RadToolTip ID="RadToolTip1" runat="server" Width="100" Height="10" TargetControlID="Label1" Position="BottomRight" Text='<%# Eval("Name")%>'>
          </telerik:RadToolTip>
      </ItemTemplate>
</telerik:RadComboBox>

C#:
protected void Page_Load(object sender, EventArgs e)
   {
 
       RadComboBox1.DataSource = CreateDataSource();
       RadComboBox1.DataTextField = "Name";
       RadComboBox1.DataValueField = "ID";
       RadComboBox1.DataBind();
   }
   protected DataTable CreateDataSource()
   {
       DataTable dataTable = new DataTable();
       dataTable.Columns.Add(new DataColumn("ID", typeof(string)));
       dataTable.Columns.Add(new DataColumn("Name", typeof(string)));
 
       DataRow dr = dataTable.NewRow();
       dr["ID"] = "1";
       dr["Name"] = "FirstName1LastName1";
       dataTable.Rows.Add(dr);
 
       DataRow dr2 = dataTable.NewRow();
       dr2["ID"] = "2";
       dr2["Name"] = "FirstName2LastName2";
       dataTable.Rows.Add(dr2);
 
       return dataTable;
   }

Thanks,
Princy.
0
Joe
Top achievements
Rank 2
answered on 08 Sep 2011, 07:26 PM
Princy,

Thanks for the response.

Im not sure that I follow. I see in your example that you have 2 columns listed (ID & Name). The Name column is associated with text field of the combobox. You are then using it for the Tooltip. What if you have a 3rd column (in my case, the tooltip is a description (DESC) of the severity (SEVERITY) column)? Would I simply swap the <%# Eval("Name")%> with <%# Eval("DESC")%>?
0
Ivana
Telerik team
answered on 13 Sep 2011, 02:41 PM
Hi Joe,

Yes, if you simply swap <%# Eval("Name")%> with <%# Eval("DESC")%> it  will work if "DESC" is name of a column in the data table you are getting data from.

Best wishes,
Ivana
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Allen
Top achievements
Rank 2
Iron
Veteran
answered on 27 Mar 2020, 04:33 PM
Works as described.  Only problem is autosizing the text for the tooltip.  How do I do that so the tip is fully displayed up to some CUTOFF limit?
0
Peter Milchev
Telerik team
answered on 31 Mar 2020, 03:16 PM

Hello Allen,

The ToolTip will resize to show all the content if the Width and Height properties are removed. Additionally, you can set max-width property to the ToolTip and optionally an overflow, if you want a scrollable content:

<style>
    .RadToolTip.RadComboBoxToolTip{
        max-width: 200px;
    }
</style>
<telerik:RadComboBox ID="RadComboBox1" runat="server" EmptyMessage="Select" DataTextField="Name">
    <ItemTemplate>
        <asp:Label runat="server" ID="Label1" Text='<%# Eval("Name")%> '></asp:Label>
        <telerik:RadToolTip ID="RadToolTip1" CssClass="RadComboBoxToolTip" runat="server" TargetControlID="Label1" Position="BottomRight" Text='<%# Eval("Name")%>'>
        </telerik:RadToolTip>
    </ItemTemplate>
</telerik:RadComboBox>

Another option is to just manipulate the string passed to the ToolTip's Text property:

<telerik:RadToolTip ID="RadToolTip1" CssClass="RadComboBoxToolTip" runat="server" TargetControlID="Label1" Position="BottomRight" Text='<%# Eval("Name").ToString().Length < 20 ? Eval("Name"): Eval("Name").ToString().Substring(0,17)+"..."   %>'>

 

Regards,
Peter Milchev
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Tags
ComboBox
Asked by
Joe
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 2
Joe
Top achievements
Rank 2
Ivana
Telerik team
Allen
Top achievements
Rank 2
Iron
Veteran
Peter Milchev
Telerik team
Share this question
or