[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Resize Combobox

Posted on 2004-10-07
10
Medium Priority
?
2,526 Views
Last Modified: 2012-05-05

i want to resize my comboboxes to match the size of the textboxes.

i've seen that i can use:
cbo.DrawMode = DrawMode.OwnerDrawFixed
cbo.ItemHeight =15

to specify a custom height.

the problem is that once i do that i can't see any items in the comboxbox dropdown. The dropdown is the correct height for the number of items, and if i click inside the dropdown it selects the text thats there, just i can't see the text.

i'm thinking i need to capture some event and maybe call the base class, just not sure which one or if i'm on the right track.
0
Comment
Question by:mpdalton
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 4

Expert Comment

by:eozz_2000
ID: 12255360
When you set the drawMode property of the comboBox to DrawMode.OwnerDrawFixed, you have to draw you items by code, you are indicating that you want to paint your control as you want, thats the reason because you see nothing.
0
 
LVL 3

Author Comment

by:mpdalton
ID: 12255691
any code snippets that might show me how to do that ?
0
 
LVL 19

Assisted Solution

by:arif_eqbal
arif_eqbal earned 500 total points
ID: 12256388
in the DrawItem Event of the ComboBox write

 e.DrawBackground()
 e.Graphics.DrawString(ComboBox1.Items(e.Index), e.Font, Brushes.Blue, New RectangleF(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height))

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 19

Expert Comment

by:arif_eqbal
ID: 12256393
sorry I wrote Brushes.Blue
it will show the Items in Blue color make it Brushes.Black
0
 
LVL 5

Assisted Solution

by:naiea1231
naiea1231 earned 1500 total points
ID: 12256396
This is what you need

   Private Sub ComboBox1_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles ComboBox1.DrawItem
        ' Set the DrawMode property to draw fixed sized items.
        ComboBox1.DrawMode = DrawMode.OwnerDrawFixed
        ' Draw the background of the ListBox control for each item.
        e.DrawBackground()
        ' Create a new Brush and initialize to a Black colored brush by default.
        Dim myBrush As Brush

        ' Determine the color of the brush to draw each item.
        myBrush = Brushes.Black

        ' Draw the current item text based on the current Font and the custom brush settings.
        e.Graphics.DrawString(ComboBox1.Items(e.Index), e.Font, myBrush, New RectangleF(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height))
        ' If the ListBox has focus, draw a focus rectangle around the selected item.
        e.DrawFocusRectangle()
    End Sub

It basically draws in all the elements of the combobox as by changing the DrawMode to OwnerDrawFixed, the operating system no longer draws in the items, and this has to be done manually. Give that a go, it will allow you to use any item height.

James
0
 
LVL 5

Expert Comment

by:naiea1231
ID: 12256405
My apologies, 3 minutes slow ;), arif_eqbal has the same code.
0
 
LVL 3

Author Comment

by:mpdalton
ID: 12272588
thanks for your replies.

the comboboxes i'm using are bound to a datatable to when the e.graphics.drawstring method is called it generates an error:

"Cast from type 'DataRowView' to type 'String' is not valid."

is it possible to use this method with a bound combobox ?
0
 
LVL 5

Accepted Solution

by:
naiea1231 earned 1500 total points
ID: 12273530
Just had a look around for you and there is a good example here:
http://www.dotnet247.com/247reference/msgs/40/203845.aspx

You'll just have to adjust the listbox to combobox, as the same commands should apply to both without any issues. Let us know how it goes.

James
0
 
LVL 5

Expert Comment

by:naiea1231
ID: 12273534
Keep in mind that example is in C#, but you can see how it applies to VB.NET, however if you need a hand converting just ask.

James
0
 
LVL 3

Author Comment

by:mpdalton
ID: 12273567
Brilliant, thanks everyone it's working perfectly now ... finally all my controls are the same height.

i'm a happy man :-)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question