I have a combo box that has 5 columns and it needs to have a Header/Title Bar to describe the columns. Is it possible to add that feature easily - the control has to remain on the form as a combo box.
An obvious way of doing this would be to add a label - or maybe five labels - just above the combo box. Provided you took care to arrange it so that the captions lined up properly with the columns, it should achieve the result you want. It might also be useful to adjust the foreground and background colours of the label(s) to make it look more obviously part of the combo.
Going further, if this was something you are likely to do more than once, you can create your own "combo with header" class. This would be a container object, holding both the labels and the combo box. The advantage is that it will bind the two controls together, allowing you to operate on them as a single unit.
Mike
__________________________________
Mike Lewis (Edinburgh, Scotland)
Thanks for the info, I was hoping I just overlooked the obvious.... I can use a label/labels, but now my issue is this combo box drops down and to the left because of it's position on the page. Is it possible to bind the label to the top left position of the drop portion of the combobox? Or to get the coordinates of the dropped portion of the combobox?
If the combo is always in the same position on the form, and if the user never resizes the form, then the fact that it drops down to the left shouldn't make any difference. The labels will always be in the same position relative the combo.
But even if that wasn't the case, you can always find the positions of the columns dynamically. You would explicitly set the column widths by means of the combo's ColumnWidths property. You know the co-ordinates the right-hand edge of the combo (by adding its Left to its Width). That's all you need to calculate where each column begins and ends (except perhaps for a minor adjustment to allow for the combo's border and the the vertical lines between the columns).
This is all an argument in favour of using the custom combo-with-labels container class that I suggested earlier. That way, you can encapsulate the necessary calculations at the class level, and not have to worry about them when designing the form.
Mike
__________________________________
Mike Lewis (Edinburgh, Scotland)
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.