How to show Tooltip text on Dropdown selection

No.of Views1306
Bookmarked0 times
Downloads 
Votes0
By  helloraj   On  16 Feb 2010 00:02:30
Tag : CSharp , List Controls
How to show Tooltip text on Dropdown selection
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 

Introduction

When you have a large text on a combo box and you want to show tooltip text while selecting an item form dropdown, there is no Dropdown property which can show a tooltip based on user selection like this.

Image Loading

But here is some simple line of code by which you can achieve it

private void comboBox1_DrawItem(object sender, DrawItemEventArgs e)
{
string DropDownText;
if (e.Index == -1)
{
DropDownText = string.Empty;
}
else{
DropDownText = this.comboBox1.GetItemText(comboBox1.Items[e.Index]);
}
e.DrawBackground();
using (SolidBrush br = new SolidBrush(e.ForeColor))
{
e.Graphics.DrawString(DropDownText, e.Font, br, e.Bounds);
}

if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
{
toolTip1.Show(DropDownText, comboBox1, e.Bounds.Right, e.Bounds.Bottom);
}
} 

Note.

 

  1. You need to change property of Dropdown , Drawmode to OwnerDrawFixed for the this /li>
Image Loading

2. Drag and Drop a tooltip to your form where this drop down exists.

Enjoy the simple article.thank you for reading.

 
Sign Up to vote for this article
 
About Author
 
helloraj
Occupation-Not Provided
Company-Not Provided
Member Type-Fresh
Location-Not Provided
Joined date-23 Jul 2009
Home Page-Not Provided
Blog Page-Not Provided
 
 
Other popularSectionarticles
Comments
There is no comments for this articles.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top