*Experts* DiverDan Posted March 12, 2003 *Experts* Posted March 12, 2003 Is it possible to add horizontal scroll bars to a dropdown list combobox when they are needed? Thanks Quote Member, in good standing, of the elite fraternity of mentally challenged programmers. Dolphins Software
bpayne111 Posted March 12, 2003 Posted March 12, 2003 hmmm good question.... have you considered a tool tip instead? you could show the tool tip whenever the word is too big just an idea Quote i'm not lazy i'm just resting before i get tired.
*Experts* DiverDan Posted March 12, 2003 Author *Experts* Posted March 12, 2003 Hi Brandon, I'd rather display horizontal scroll bars only when they are needed, which will be rare. I'm finishing the conversion calculator portion of my project and the telecommunications catagory presented some very long, lengthy items (does that say something about hardware guys?). This is the only catagory that presents this problem. I've used tool tips for explaining entry error corrections to the user, so that idea is out, or maybe not if there is no way of doing this. Thanks Dan Quote Member, in good standing, of the elite fraternity of mentally challenged programmers. Dolphins Software
*Experts* Nerseus Posted March 12, 2003 *Experts* Posted March 12, 2003 (edited) You can set the ComboBox's DropDownWidth property, probably the closest thing you'll find. You'll probably want to compute the text length to find the maximum sized string. Here's a C# code sample that may work for you: comboBox1.Items.Add("hello world"); comboBox1.Items.Add("blah"); comboBox1.Items.Add("Show me a sane man and I will cure him for you"); Graphics g = comboBox1.CreateGraphics(); float maxSize = -1f; SizeF size = new SizeF(); foreach(object o in comboBox1.Items) { size = g.MeasureString(o.ToString(), comboBox1.Font); if(size.Width > maxSize) maxSize = size.Width; } g.Dispose(); comboBox1.DropDownWidth = (int)maxSize; You could check the maxSize against the current control Width and only set the DropDownWidth if it's bigger - that way you don't get a tiny drop down portion... -Ner Edited March 12, 2003 by Nerseus Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
*Experts* DiverDan Posted March 12, 2003 Author *Experts* Posted March 12, 2003 Thanks Nerseus, I've pretty much already maxed the comboxes length in relation to the form size. But, your idea might work okay. I'll give it a try and see how it shows in relation to the other controls near the combo box. Thanks, Dan Quote Member, in good standing, of the elite fraternity of mentally challenged programmers. Dolphins Software
*Experts* Nerseus Posted March 12, 2003 *Experts* Posted March 12, 2003 It shouldn't be any larger when it's not dropped down, but when dropped down it might overlay some other information. It's still better than the technique I used in VB3 where we made the whole control wider while dropped down, then shrink when closed - very nasty looking :) -Nerseus Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.