Add ToolTip for ComboBox Control in C#

 

In C# win forms ComboBox does not have property to add tooltip for individual items. So we have to write our own logic to add tooltip for ComboBox items. In this article we discuss about how to add tooltip for ComboBox Items. We can add tooltip for comboBox control items by using DrawItem event. 

Create C# windows application and name it as “ComboboxToolTip”. Add one ComboBox control and name it as “cmbEmployees”. Now items to cmbEmployees control by selecting Items property of the combobox control as shown below.

                    

 

 

Now add “DrawItem” event for cmbEmployees control as shown below.

 

                            

 

Change the cmbEmployees control property DrawMode to “OwnerDrawFixed” as shown below.

 

                               

 

Add one more control ToolTip to the form as shown below and name it as “toolTip”.

 

                           

 

Now add below code for cmbEmployees control DrawItem event to display the tooltip for ComboBox control items.

using System.Drawing; 

using System.Windows.Forms;

 

namespace ComboboxToolTip 

{ 

    public partial class Form1 : Form 

    { 

        public Form1() 

        { 

            InitializeComponent(); 

        }

 

        private void cmbEmployees_DrawItem(object sender, DrawItemEventArgs e) 

        { 

            if (e.Index == -1) { return; } 

            Point p = new Point(cmbEmployees.Location.X + 120, cmbEmployees.Location.Y + cmbEmployees.Height + (30 + e.Index * 10));

 

            if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) 

            { 

                toolTip.Show(cmbEmployees.Items[e.Index].ToString(), this, p); 

            }

 

            e.DrawBackground(); 

            e.Graphics.DrawString(cmbEmployees.Items[e.Index].ToString(), e.Font, Brushes.Black, new Point(e.Bounds.X, e.Bounds.Y)); 

        } 

    } 

}

 

Execute the application and select any item from the cmbEmployess comboBox control, it displays the tooltip as shown below.

 

                     

                                                                                                                               ComboboxToolTip.zip (41.16 kb)