C# .NET - Tooltip on combobox dropdown items

Asked By Lakshmi Ramya
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
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
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
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
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
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
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
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);

}

}

}

Create New Account
help
wondering if there was a better way? Thanks. - - John .NET WinForms Controls Discussions OnMouseHover (1) EventHandler (1) OnMouseLeave (1) UserControl (1) SetToolTip (1) EventArgs (1) ToolTip.SetToolTip (1) SetButtonToolTip (1) Hi John, Based on my understanding, you have a UserControl with some on the Form1. public partial class UserControl1 : UserControl { public UserControl1() { InitializeComponent(); this.label1.MouseHover + = new EventHandler(label1_MouseHover); this.label1.MouseLeave + = new EventHandler(label1_MouseLeave); } void label1_MouseLeave(object sender, EventArgs e) { this.OnMouseLeave(e); } void label1_MouseHover(object sender, EventArgs e) { this.OnMouseHover(e); } } public partial class Form1 : Form { public Form1() { InitializeComponent(); this.userControl11.MouseHover
textbox is create dynamically and the event is wired up private void Form1_Load( object sender, EventArgs e) { TextBox txtMyTest = new TextBox (); txtMyTest.Text = "My Test" ; this .Controls.Add(txtMyTest); txtMyTest.MouseHover + = new EventHandler (txtMyTest_MouseHover); } private void txtMyTest_MouseHover( object sender, EventArgs e) { MessageBox .Show( "Mouse hovered. . ." ); } Also, refer http: / / msdn.microsoft.com / en-us / library / system add a ToolTip control to ur fomr from ToolBox and private void textBox1_MouseHover(object sender, EventArgs e) { toolTip1.Show(textBox1.Text, textBox1); } Add or create a "tooltip" control on your form the sender object. Use the following code snippet for this:- private void txtMyTest_MouseHover( object sender, EventArgs e) { TextBox txt = ( TextBox )sender; toolTip1.SetToolTip(txt, txt.Text); } So, the above event could be wired up to multiple textboxes in
Forms.CurrencyManager.EndCurrentEdit() at System.Windows.Forms.BindingSource.EndEdit() at HIP2007.AddEditMasterTask.btnSave_Click(Object sender, EventArgs e) in M: \ HIP2007 \ HIP2007 \ Dialogs _ CurrentWork \ AddEditMasterTask.cs:line 92 at System.EventHandler.Invoke(Object sender, EventArgs e) at System.Windows.Forms.Control.OnClick(EventArgs e) at System.Windows.Forms.Button.OnClick EventArgs e) at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) at System.Windows.Forms.Control.WmMouseUp also written a test project trying to reproduce your problem: private void Form1_Load(object sender, EventArgs e) { DataTable dt = new DataTable(); dt.Columns.Add(new DataColumn("column1", typeof(int))); dt.Columns dateTimePicker1.DataBindings.Add( new Binding("Value", this.bindingSource1, "column2", true)); } private void button1_Click(object sender, EventArgs e) { this.bindingSource1.MoveNext(); } private void button2_Click(object sender, EventArgs e) { this.bindingSource1.EndEdit(); } However, it works well without any problem. Basically, DateTimePicker.Value property
myFileDialogButton.TabIndex = 34; this.myFileDialogButton.Text = ". . ."; this.myFileDialogButton.UseVisualStyleBackColor = true; this.myFileDialogButton.Click + = new System.EventHandler(this.myFileDialogButton_Click); / / / / myFileBox / / this.myFileBox.CausesValidation = false; this.myFileBox.Location = new System.Drawing.Point(297 TabIndex = 32; this.myRecordButton.Text = "Record"; this.myRecordButton.UseVisualStyleBackColor = true; this.myRecordButton.Click + = new System.EventHandler(this.myRecordButton_Click); / / / / myStopButton / / this.myStopButton.Location = new System.Drawing.Point(297, 493); this.myStopButton.Name TabIndex = 31; this.myStopButton.Text = "Stop"; this.myStopButton.UseVisualStyleBackColor = true; this.myStopButton.Click + = new System.EventHandler(this.myStopButton_Click); / / / / myPlayFileButton / / this.myPlayFileButton.Location = new System.Drawing.Point(209, 544); this.myPlayFileButton.Name 30; this.myPlayFileButton.Text = "Play File"; this.myPlayFileButton.UseVisualStyleBackColor = true; this.myPlayFileButton.Click + = new System.EventHandler(this.myPlayFileButton_Click); / / / / myPlayButton / / this.myPlayButton.Location = new System.Drawing.Point(123, 544); this.myPlayButton.Name 29; this.myPlayButton.Text = "Play Live"; this.myPlayButton.UseVisualStyleBackColor = true; this.myPlayButton.Click + = new System.EventHandler(this.myPlayButton_Click); / / / / myUrlBox / / this.myUrlBox.CausesValidation = false; this.myUrlBox.Location = new System.Drawing.Point(123 public Form1() { InitializeComponent(); this.Visible = true; this.Update(); this.Show(); / / Tooltip Setup #region ToolTips toolTip17.SetToolTip(label7, "This section of controls is for editing the settings"); toolTip18.SetToolTip(myTypeBox, "Provides functionality for different video formats"); toolTip19.SetToolTip(myFileDialogButton, "Click here to choose a location that will store recorded videos"); toolTip20.SetToolTip(myFileBox