C# .NET - Tooltip on combobox dropdown items

Asked By Lakshmi Ramya on 21-Oct-10 01:02 AM
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. 
Nowshad M replied to Lakshmi Ramya on 21-Oct-10 01:11 AM
Hi,

You can use thr mouse hover event of the control like below

private void comboBox1_MouseHover(object sender, EventArgs e)
        {
            MessageBox.Show(comboBox1.SelectedIndex.ToString());
        }


Thanks,
Nowshad
karthik karthik replied to Lakshmi Ramya on 21-Oct-10 01:16 AM
hi

for (int i = 0; i < ds.Tables[0].Rows.Count; i++)

{

DropDownList1.Items[i].Attributes.Add("Title", ds.Tables[0].Rows[i]["empname"].ToString());

}

DropDownList1.ToolTip = DropDownList1.SelectedItem.Text;



try This this will come the corresponding tooltip  in the drop down list......
Lakshmi Ramya replied to Nowshad M on 21-Oct-10 01:20 AM
Thank you for your immediate reply Nowshad.
The event is hiring only on hover of combobox selected item. but what i need is on the items in the dropdown.
Lakshmi Ramya replied to karthik karthik on 21-Oct-10 01:23 AM
Thanks for replying karthik.
What i need is on combobox dropdown in C#.NET that too on dropdown items. let me know if you need more clarification.

Nowshad M replied to Lakshmi Ramya on 21-Oct-10 01:33 AM
Hi,
Just let me know one thing.
You are askin in Asp.Net or for windwos application?


Thanks,
Nowshad

karthik karthik replied to Lakshmi Ramya on 21-Oct-10 01:48 AM
hi

con = new SqlConnection("Server=dcpldb;database=sample;uid=dbteam;pwd=dbteam");

con.Open();

SqlDataAdapter da = new SqlDataAdapter("select tblkey+' '+empkey as final,empname from tablename11 order by tblkey", con);

DataSet ds = new DataSet();

da.Fill(ds);

DropDownList1.DataSource = ds.Tables[0];

DropDownList1.DataValueField = "final";

DropDownList1.DataTextField = "final";

DropDownList1.DataBind();

for (int i = 0; i < ds.Tables[0].Rows.Count; i++)

{

DropDownList1.Items[i].Attributes.Add("Title", ds.Tables[0].Rows[i]["empname"].ToString());

}

DropDownList1.ToolTip = DropDownList1.SelectedItem.Text;


actually in this coding what i have used is in the dropdownlidt the empane will be loaded and the corresponding key will shown on the tooltip items corresponding dropdownlistitems loaded in dropdownlist.......
Check this.......
Lakshmi Ramya replied to karthik karthik on 21-Oct-10 02:12 AM
I think you are using ASP.NET. where as i dont have any option to dropdownlist in my toolbox. I am working on C#.NET where i use Combobox which i have added the content manually. Here is my code with a simple combobox.

using System;

using System.Drawing;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

using System.Data;

namespace Combobox_tooltip

{

/// <summary>

/// Summary description for Form1.

/// </summary>

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

//

}

/// <summary>

/// Clean up any resources being used.

/// </summary>

protected override void Dispose( bool disposing )

{

if( disposing )

{

if (components != null)

{

components.Dispose();

}

}

base.Dispose( disposing );

}

#region Windows Form Designer generated code

/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

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

/// <summary>

/// The main entry point for the application.

/// </summary>

[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);

}

}

}