Click here to Skip to main content
15,887,337 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:

How do I highlight or display some text like "select item" or "select name" in a combobox in a light gray color in such a way that whenever I click anywhere on the combobox, the text should be cleared and the drop down list opens?

Posted
Updated 22-Nov-09 8:25am
v2

You can set the selected text property for the combobox and clear it in the Enter event.
 
Share this answer
 

well there is probably half a dozon answers for this but i did a quick run through and 4-5 minutes later i think i have a solution for you.
make the forecolor of your textbox silver or what ever you originally wanted. next set the DropDown style to dropdown this will allow you to have an initial text value that is not in your list. soooo now we are going to use PInvoke...
the function we wil use is:

[DllImport("user32.dll")] We also nee to add this constant.
public static extern int SendMessage(int hWnd, int msg, int wParam, IntPtr lParam);

public const int CB_SHOWDROPDOWN = 0x14F;

Now add a combobox mousedown event to your code.

private void comboBox1_MouseDown(object sender, MouseEventArgs e) <br />{ <br />comboBox1.ForeColor = SystemColors.WindowText;<br />SendMessage(comboBox1.Handle.ToInt32(), CB_SHOWDROPDOWN, 1, IntPtr.Zero);
}

it may be worth throwing this line in the selected index change.

(some other control on the form).focus();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900