| I need an event to be raised when mouse hovers over Combo Box
items so that I could provide ToolTip for Items of dropDownArea of ComboBox.
how to get index of comboBoxItem pointed by cursor ? Thanks in advance. |
Loading
| I need an event to be raised when mouse hovers over Combo Box
items so that I could provide ToolTip for Items of dropDownArea of ComboBox.
how to get index of comboBoxItem pointed by cursor ? Thanks in advance. |
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Manikavelu VelayuthamRank #413 · 6K reputationPosted Oct 20, 2010, 9:32 PM EDT
//
// This method binds tooltip with a dropdown/ any list control
//
public static void BindTooltip(ListControl lc) { for (int i = 0; i < lc.Items.Count; i++)
{
lc.Items[i].Attributes.Add("title", lc.Items[i].Text);
}
}
Lakshmi Ramya16 reputationPosted Oct 20, 2010, 9:57 PM EDT
can we have the same for combobox??
Manikavelu VelayuthamRank #413 · 6K reputationPosted Oct 20, 2010, 10:01 PM EDT
Lakshmi Ramya16 reputationPosted Oct 20, 2010, 10:12 PM EDT
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace Combobox_tooltip
{
///
/// Summary description for Form1.
///
public class Form1 : System.Windows.Forms.Form
{
private ToolTip toolTip1;
private System.Windows.Forms.ComboBox comboBox1;
private System.ComponentModel.IContainer components;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
this.SuspendLayout();
//
// comboBox1
//
this.comboBox1.Items.AddRange(new object[] {
"ramya",
"lakshmiramya",
"abcdefghijklmnopqrstuvwxyz",
"abcdefghijklm",
"abcdefghijklmraqeewf",
"yxwvutsrqponmlkjihgf",
"zyxwvutsrqponmlkjihgfedcba"});
this.comboBox1.Location = new System.Drawing.Point(64, 56);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(121, 21);
this.comboBox1.TabIndex = 0;
this.comboBox1.Text = "comboBox1";
this.toolTip1.SetToolTip(comboBox1,comboBox1.Text);
this.comboBox1.MouseHover += new System.EventHandler(this.comboBox1_MouseHover);
this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
//
// toolTip1
//
this.toolTip1.AutoPopDelay = 0;
this.toolTip1.InitialDelay = 0;
this.toolTip1.ReshowDelay = 0;
this.toolTip1.ShowAlways = true;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.comboBox1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
toolTip1.SetToolTip(comboBox1,comboBox1.SelectedItem.ToString());
}
private void comboBox1_MouseHover(object sender, EventArgs e)
{
MessageBox.Show(comboBox1.SelectedText);
}
//
// This method binds tooltip with a dropdown/ any list control
//
public static void BindTooltip(ListControl lc)
{
for (int i = 0; i < lc.Items.Count; i++)
{
lc.Items[i].Attributes.Add("title", lc.Items[i].Text);
}
}
}
}
Manikavelu VelayuthamRank #413 · 6K reputationPosted Oct 20, 2010, 10:51 PM EDT
for (int i = 0; i < DropDownList1.Items.Count; i++)
{
DropDownList1.Items[i].Attributes.Add("title", DropDownList1.Items[i].Text);
}
Lakshmi Ramya16 reputationPosted Oct 20, 2010, 11:00 PM EDT
for (int i = 0; i < comboxBox1.Items.Count; i++)
{
//DropDownList1.Items[i].Attributes.Add("title", DropDownList1.Items[i].Text);
}
Manikavelu VelayuthamRank #413 · 6K reputationPosted Oct 20, 2010, 11:19 PM EDT
Is it a Windows Application or Web Application ?
Lakshmi Ramya16 reputationPosted Oct 20, 2010, 11:27 PM EDT
Manikavelu VelayuthamRank #413 · 6K reputationPosted Oct 20, 2010, 11:33 PM EDT
You can put a label next to combobox and display the items text in it after selecting the item from the combobox.
Thats it you cand do.
Suthish NairRank #92 · 22.8K reputationPosted Oct 20, 2010, 11:56 PM EDT
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged Dim ToolTip1 As New ToolTip ToolTip1.SetToolTip(ComboBox1, ComboBox1.SelectedItem) ToolTip1.AutoPopDelay = 5000 ToolTip1.InitialDelay = 1000 ToolTip1.ReshowDelay = 500 ToolTip1.ShowAlways = True End Sub but if you need formating refer linkManikavelu VelayuthamRank #413 · 6K reputationPosted Oct 21, 2010, 12:29 AM EDT
Window that popup on hover of the mouse is called tool tip.
Thats why i preferred to have a label to display the item name fully.
Lakshmi Ramya16 reputationPosted Oct 21, 2010, 12:40 AM EDT
Suthish NairRank #92 · 22.8K reputationPosted Oct 21, 2010, 1:41 AM EDT
My first reply with an example is because of you said its not supported.
Now about MouseHover, did you tried to test the code before posting replys.
You can use MouseHover event to show the toolitips also.
Private Sub ComboBox1_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.MouseHover Dim ToolTip1 As New ToolTip Dim caption As String = "Selected value is: " & ComboBox1.SelectedText ToolTip1.SetToolTip(ComboBox1, caption) ToolTip1.AutoPopDelay = 5000 ToolTip1.InitialDelay = 200 ToolTip1.ReshowDelay = 100 ToolTip1.ShowAlways = True End SubManikavelu VelayuthamRank #413 · 6K reputationPosted Oct 21, 2010, 1:55 AM EDT
This event will fire on mouse hover of the combo box and not on mouse hover of the selection list.
I tried this already.
Suthish NairRank #92 · 22.8K reputationPosted Oct 21, 2010, 2:14 AM EDT
At any point of logic there will a value binded to the CombobBox,
that will a SelectedItem, SelectedText, SelectedValue or simply Text.
you can use following....
Dim caption As String = vbCrLf & "Selected value is: " & vbCrLf & ComboBox1.Text & vbCrLf Dim caption As String = "Selected value is: " & ComboBox1.SelectedItem Dim caption As String = "Selected value is: " & ComboBox1.SelectedText Dim caption As String = "Selected value is: " & ComboBox1.SelectedValueSuthish NairRank #92 · 22.8K reputationPosted Oct 21, 2010, 2:38 AM EDT
Private Sub ComboBox1_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.MouseHover If ComboBox1.SelectedItem <> "" Then Dim ToolTip1 As New ToolTip Dim caption As String = "Selected value is: " & ComboBox1.SelectedItem Dim lbl As New Label lbl.BackColor = System.Drawing.Color.RoyalBlue.RosyBrown lbl.Text = caption ComboBox1.Controls.Add(lbl) ComboBox1.Controls.Item(0).BringToFront() ComboBox1.Controls.Item(0).Width = 200 ComboBox1.Controls.Item(0).Height = 100 ToolTip1.SetToolTip(ComboBox1, "") ToolTip1.AutoPopDelay = 5000 ToolTip1.InitialDelay = 200 ToolTip1.ReshowDelay = 100 ToolTip1.ShowAlways = True End If End Sub Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove ComboBox1.Controls.Clear() End SubManikavelu VelayuthamRank #413 · 6K reputationPosted Oct 21, 2010, 2:40 AM EDT
I have uploaded the sample screen shot of what i would like to say. Just view the image, you will come to know.
Above code will display the tool tip after the selection of item from the list. Once you selected the item, if you move your mouse over the combo box, tooltip will be shown.
But it wont show the tooltip when you move the mouse over the selection items of the combo box as shown in the image.
krishnan sriram2 reputationPosted Nov 5, 2010, 8:46 AM EDT
There are 2 ways by which you can see tooltips for the dropdown items of a combobox.
1. Create a customControl - If you desire to have your style, font, background for tooltips
2. Override DrawItem of combobox
I have taken Item 2 and here's a simple example. You may need to play around with the X & Y xo-orinates to get things right
private void cbLongTexts_DrawItem(object sender, DrawItemEventArgs e) { if (e.Index == -1) { return; } //cbLongTexts.PointToClient(new Point(Control.MousePosition.X + e.Bounds.Width, Control.MousePosition.Y + e.Bounds.Height)) Point p = new Point(cbLongTexts.Location.X, cbLongTexts.Location.Y + cbLongTexts.Height); //user mouse is hovering over this drop-down item, update its data if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) { // this tooltip simply shows the displayed text to the right of the drop-down box, customize as needed toolTip1.Show(cbLongTexts.Items[e.Index].ToString(), this, //new Point(e.Bounds.X + e.Bounds.Width, e.Bounds.Y)); p); } e.DrawBackground(); // draw text strings e.Graphics.DrawString( cbLongTexts.Items[e.Index].ToString(), e.Font, Brushes.Black, new Point(e.Bounds.X, e.Bounds.Y)); }Here are some things that you may want to know before you use this code 1. Make sure the Combobox DrawMode is set to "OwnerDrawFixed" 2. Move over to the events section of the combobox (In my case it was cbLongTexts) and look for the event DrawItem and the rest of what needs to be done within the function is in there for you to witness and execute Have fun.pooja chavan11 reputationPosted Oct 19, 2014, 5:30 PM EDT
Hi All,
I want to show tooltip for Comboboxedit control of devexpress can anyone help me? I am still unable to fix it even after following all above suggestions
need urgent help/suggestion
Appreciate all ur help