views:

2834

answers:

2

Hi

I just want to add a tooltip for each item in a combo box. i am using c#.net windows application.

There is no option like

combobox.items[1].tooltip();

Is there any way to add tooltip it ?

A: 

You will need to create your own UserControl.

Having a ToolTip for each item in a combobox is an unusual requirement; perhaps you could use a 2 column combobox instead?

Mitch Wheat
How do you do a two-column combo?
Assaf Lavie
There are a few free ones around. Found this one on codeproject but I haven't used it and I can't comment on how good it is: http://www.codeproject.com/KB/cpp/multicolumncombo.aspx
Mitch Wheat
A: 

private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e) { ToolTip toolTip1 = new ToolTip(); toolTip1.AutoPopDelay = 0; toolTip1.InitialDelay = 0; toolTip1.ReshowDelay = 0; toolTip1.ShowAlways = true; toolTip1.SetToolTip(this.comboBox1, comboBox1.Items[comboBox1.SelectedIndex].ToString()) ; }

Vasu
Although this will work, it will also create a strong connection between the tooltip (which you now have no way of accessing being that you created it without assigning it to a variable). So if you try to remove to comboBox. Although it will remove from sight. It will stay in memory. Not only that, you're compounding ties with new tooltips every time you change index. I'd take the Tooltip to a higher scope and simply call like this:private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e) {myGolbalToolTip.SetToolTip(this.comboBox1, yourString);
Psytechnic
That way, inside or outside of the scope, you can call myGlobalToolTip.RemoveAll() to remove all connections and then remove the control from memory. But that's only if you're dynamically creating objects.
Psytechnic