Click here to Skip to main content
15,884,960 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm looking for an option with which I can view large amount of options in combobox in parallel way !!! sorry for my bad english , but i use photo shop to explain my idea .

http://i.stack.imgur.com/214Q0.png

again the above pic was done by photoshop not with vb :)

I use this code two display items in combobox and centralize header items


VB
Private Sub ComboBox3_DrawItem(sender As Object, e As DrawItemEventArgs) Handles ComboBox3.DrawItem

    If Not e.Index < 0 Then

        e.DrawBackground()
        Dim text As String = CType(sender, ComboBox).Items(e.Index).ToString()

        If text.StartsWith("=") Then

            Dim f As New Font(CType(sender, ComboBox).Font, FontStyle.Bold)
            TextRenderer.DrawText(e.Graphics, text, e.Font, e.Bounds, Color.Maroon)

        Else

            Dim f As New Font(CType(sender, ComboBox).Font, FontStyle.Regular)
            TextRenderer.DrawText(e.Graphics, text, e.Font, New Point(e.Bounds.X, e.Bounds.Y), Color.Black)

        End If

    End If

End Sub


the above code worked fine but i can't draw items in multiple columns .

so, any help ???? thanks in advance :)

sorry for my bad English again
Posted
Comments
TnTinMn 11-Nov-13 19:43pm    
Why re-invent?
http://www.bing.com/search?q=multicolumn+combobox+codeproject&qs=n&form=QBRE&pq=multicolumn+combobox+codeproject&sc=1-32&sp=-1&sk=&cvid=f1a803ca34384d9bbc8a5a21863c33be

You have several to choose from.
Matt T Heffron 11-Nov-13 20:23pm    
I don't think that's the same as what OP is asking for.
It appears that what is wanted is for an otherwise very tall drop list to be split into multiple columns (with unselectable section headers also).

Why using a combo box? A well-known multi-column control is System.Windows.Forms.ListView:
http://msdn.microsoft.com/en-us/library/system.windows.forms.listview%28v=vs.110%29.aspx[^].

There are some other possibilities. You can use two combo boxes bound with events and arranged appropriately, you can create a custom control, which would not really be too hard to make.
See, for example, this CodeProject article: Multi-Column ComboBox[^].

[EDIT]

dr_aliragab asked:
…any hint to create a custom control?
I'm not still convinced that this is necessary as we did not discuss your required features in depth, but let's assume you need it.

First, you should create a data structure to hold data in this control, its data model. First of all, you need to introduce the concept of "selection", which is always inner to the control.

Now, to render graphics, define the columns, their headers, location of items, depending on control size, you need to override the virtual method System.Windows.Forms.Control.OnPaint. I mean it: not just handling the Paint event, if you want to leave the possibility to handle this event by the control's user. In this case, the event will be invoked when you call base.OnPaint. The
event arguments parameter will give you ClipRectangle (this way you know the control size at the moment of rendering, and only its client part) and the instance of the class System.Drawing.Graphics you will use to draw everything on the control.

Please see:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.onpaint(v=vs.110).aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.paint(v=vs.110).aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.painteventargs%28v=vs.110%29.aspx[^],
http://msdn.microsoft.com/en-us/library/system.drawing.graphics(v=vs.110).aspx[^].

Now, if you need only one scroll bar (common scrolling for both columns) you can simply use default scrolling by deriving your control from System.Windows.Forms.ScrollableControl:
http://msdn.microsoft.com/en-us/library/system.windows.forms.scrollablecontrol%28v=vs.110%29.aspx[^].

In other, more complex cases, you would need to add scroll bars explicitly as children of your control: http://msdn.microsoft.com/en-us/library/system.windows.forms.scrollbar%28v=vs.110%29.aspx[^].

On top of that, to define all the functionality, you would need to handle mouse and keyboard events, pretty much all of them, or most. You will need to use this handling to operate selection (first of all), scroll, navigate and edit item if needed and allowed.

Keep in mind that nearly all the operations performed via user input should be doubled by the method for programmatic manipulations, such as Select, and so on.

From within all these handler methods, you need to invalidate the view each time you change you data model the way it requires the change of view. This is done via the Control.Invalidate methods:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.invalidate%28v=vs.110%29.aspx[^].

That's all, in the very general features.

—SA
 
Share this answer
 
v2
Comments
dr_aliragab 12-Nov-13 4:26am    
OK , but with this combobox the user can't pick an item from a column, only a row.
and with list view is the same problem, the list view is very tall and i want to split it
Sergey Alexandrovich Kryukov 12-Nov-13 10:20am    
Wait a second... which one? If you mean the one from the CodeProject article, it is a multi-column combo box. A row is an item. What do you mean by "picking an item from a column", exactly? If you need two independent columns, it could not be called "multi-column combo box", it would be two combo-boxes...
—SA
dr_aliragab 12-Nov-13 12:06pm    
yes , I mean two independent columns
Sergey Alexandrovich Kryukov 12-Nov-13 12:55pm    
This is not exactly how you explained it in first place. If they are independent, two-column control makes no sense. Isn't it obvious? Then the solution would be two separate combo-boxes, aligned and, if you want, even synchronized together with events. This is also covered by by answer, could you notice that? :-)
—SA
dr_aliragab 12-Nov-13 17:29pm    
mmmm it seems that i can't do it with combobox :(
I will explain it more , i have a long list of options , and the user must chose one , now i want to display these options in a way like the pic in my post , or some thing like that , because default combobox or listview make a long list of items :)

is my english clear ??? :) :)
i think not possible wth the combo box thankuu
 
Share this answer
 
Comments
dr_aliragab 15-Nov-13 18:28pm    
thank you
I think it is a good idea to shift to WPF. You will be able to manipulate any control to the level of of your desire.

Ever since I have shifted to WPF, everything is simple.
 
Share this answer
 
Comments
dr_aliragab 15-Nov-13 18:28pm    
how to start with WPF
Try this:

msdn.microsoft.com/en-us/library/ee649089(v=vs.110).aspx‎

msdn.microsoft.com/en-us/library/ms752299(v=vs.110).aspx

msdn.microsoft.com/en-us/library/vstudio/dd547149.aspx‎

msdn.microsoft.com/en-us/library/vstudio/dd465159.aspx‎
 
Share this answer
 
v2

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