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