Click here to Skip to main content
Click here to Skip to main content

ExCB - Extended Multi Column ComboBox

, 5 Dec 2014 CPOL
Rate this:
Please Sign up or sign in to vote.
Presenting an easy-to-use, flexible, filterable ComboBox, managing various data types (including images), also sortable, resizable and reordable columns

Sample Image - maximum width is 600 pixels

Introduction

This component, written in VB.NET, was first produced in 2008. But recently, I decided to introduce some new features, especially in the ListView part. Some reasons are listed below:

  • The need to present Images and good 'CheckBoxes', not just those resulting from the use of characters from the Wingdings font.
  • The need to automatically adjust the height of the subcomponents, given the use of different fonts and font sizes.
  • The need to 'correctly' sort Text, Numeric and Date(Time) Columns.
  • A fact which irritated everyone: with Visual Studio 2008 on Windows XP, increasing the font size did not change the height of the ListView header. Annoying... So, I also decided to impose the Header Height.

Thus, the control became, not only 'one more ComboBox', but an enhanced, flexible, powerful and easy-to-use component.

  • It works with various types of data: Text, Numbers, Date(Time), Images and Booleans
  • Images can be sent as (real) images or by path reference
  • Booleans are shown as 'checkboxes', but in 2 ways: by picture (better aspect, scalable), or by characters from Wingdings font (higher performance)
  • Has a built-in Row Counter
  • Rows can be filtered, in order to reduce the list, by typing characters in the TextBox
  • The user can control the List Header Height and Colors
  • The user can control the List Rows Height
  • The user can control each Column's Fore & Back Colors
  • The user can control the Size and SizeMode of Images and 'picture checkboxes'
  • Columns can be Resized, Reordered and Sorted (ascending/descending, with Arrow indicator)
  • Numbers and Dates are 'effectively' ordered, regardless of the Format in which they are displayed

Of course, the more images are added, the worse the performance...

Programming

Also, the code is as simple as possible, and programmers can find some useful code snippets, related to:

  • Expandable properties
  • Fading effects
  • Color change
  • Embedded controls handling
  • HeaderControl subclassing (NativeWindow)
  • HDM_LAYOUT capture
  • Header Height control
  • Header Sort Arrows
  • Columns Text, Date & Numeric effective sorting

See Documentation and Examples

First of all, download the .ZIP file.

The .ZIP file includes ExCB_Documentation.PDF, which fully describes the component.
The demo forms present several examples, techniques and tips to manipulate data.

Last Updates

  1. Addendum to ExCB_Documentation.PDF:
    Filtering - To reset filtering, selecting all Rows, just drop-down the List clicking the mouse right-button.
  2. When starting the provided solution, if you receive the message 'A project with an Output Type of Class Library cannot be started directly', then:
    Go to the Solution Explorer, select ExCB_Test Project, right-click mouse button and click Set as StartUp Project.
  3. Addendum to ExCB_Documentation.PDF: Take note of another Event:
    Event DropDownChanged - Occurs when the List is Opened/Closed.
    Syntax:
    	DropDownChanged(IsDroppedDown as Boolean)
    Remarks:
    - IsDroppedDown = True - The List was Opened
    - IsDroppedDown = False - The List was Closed
  4. To avoid an error, in a very specific circumstance, please,
    in Class ExCB.vb, Property SelectedIndex(), replace the line:
    	MyLV1.Items(value).Selected = True
    with:
    	Try
    	    MyLV1.Items(value).Selected = True
    	Catch
    	End Try
  5. In response to questions posed by L.Botello:
    1. ...it seems that, in certain circumstances, when font size is increased, the list is slightly truncated (bottom). Isn't?
      Yes, it's a bug. To fix it, please:
      in ExCB.vb, Region "TextBox & Button code", Sub Button1_MouseDown, replace the line:
      Dim LX As Integer = Sizes_.ListHeader_Height + 1 + MX * (_ListRowHeight + 1)
      
      with:
      Dim LX As Integer = Math.Max(Sizes.ListHeader_Height, _
                              TextRenderer.MeasureText(" ", Me.Font).Height + 4) + _
                              MX * (_ListRowHeight + 1)
      
    2. Did you ever have considered the possibility of growing/shrink the list (regardless of MaxRowsDisp property value) when the form is resized?
      Thank you for the suggestion, that will improve control's features.
      It will be an option. Please, do the following:
      in Class ExCB.vb, Region "Public Methods", insert the following Sub:
      Public Sub AdjustListHeight()
          Try
              Dim Parent_csH As Integer = Me.ParentForm.ClientSize.Height ' Exclude TitleBar and Borders
              Dim HeaderH = Math.Max(Sizes.ListHeader_Height, TextRenderer.MeasureText(" ", Me.Font).Height + 4)
              Dim RestH As Integer = Parent_csH - Me.Top - MyLV1.Top - HeaderH
              _MaxDsp = RestH \ (_ListRowHeight + 1)
              Dim MinRows As Integer = Math.Min(_MaxDsp, MyLV1.Items.Count + 1)
              If MyLV1.Visible Then
                  MyLV1.Height = HeaderH + MinRows * (_ListRowHeight + 1)
                  Me.Height = _LblBoxH + MyLV1.Height
              Else
                  _HideLV()
              End If
          Catch
          End Try
      End Sub
      
      Then, in your Form, insert this code and invoke the Method just for the Control instance(s) you want the feature active:
      Private Sub Me_Sizes(sender As Object, e As EventArgs) Handles Me.Resize, Me.SizeChanged
          ExCB1.AdjustListHeight()
          ' ...
          ' ExCBn.AdjustListHeight()
      End Sub
      
      Anyway, define MaxRowsDisp value for the first display (when it occurs before the first resize...).

Using the Code

The component is provided in 2 versions: Visual Studio 2008 and Visual Studio 2012.
All features are available in both versions, but version 2012 is less limited and easier to use.

The component DLL is located at ...\ExCB\VS20xx\ExCB\bin\Release\ExCB.dll.

  • Add it to your Toolbox, right-clicking the Toolbox area -> Choose Items… -> Browse -> select the DLL
  • In the Solution Explorer, select your Project, open My Project -> References -> Add… -> Browse -> select the DLL
  • Drag the component from the Toolbox to your Form.

Brief Description of the Component's Own Properties, Event and Methods

Browsable Properties

  • BorderStyle The BorderStyle which applies to the TextBox subcomponent
  • Colors (Expandable Property)
    • HeadBackColor - BackColor of the ListView Header
    • HeadForeColor - ForeColor of the ListView Header
    • ListBackColor - BackColor of the ListView Items
    • ListForeColor - ForeColor of the ListView Items
    • TBoxBackColor - BackColor of TextBox element
    • TBoxForeColor - ForeColor of TextBox element
  • CounterLoc - The position and alignment of the built-in Row Counter, relative to the TextBox
  • DisplayColumn - The Index of the SubItem (Column) to display in the TextBox, when selecting a Row in the List
  • Filterable - Indicates if the ListView Rows can/cannot be filtered
  • Font - Defines the Font Name, Size and Styles for ALL the subcomponents (ListView, TextBox and Counter)
  • GridLines - Displays grid lines around Items and SubItems, in the ListView
  • MaxRowsDisp - Maximum number of Rows to display, when the List is dropped-down
  • MinimunWidth - Minimum Width of the component. Changes when the component is resized
  • Read_Only - When True, the component cannot be dropped-down / changed, but shows the current selection
  • Reordable - Indicates if the ListView Columns can/cannot be reordered
  • Resizable - Indicates if the ListView Columns can/cannot be resized
  • Sizes - (Expandable Property)
    • Image_Height - Height of the Images sent to the List
      • Image_Width - Width of the Images sent to the List
      • ListHeader_Height - Height of the ListView Header
      • ListRow_Height - Height of the ListView Rows
      • YesNo_Height - Height (and Width) of the "checkboxes"
  • Sortable Indicates if the ListView Columns can/cannot be sorted

Non-browsable Properties

  • Count - Gets the number of Rows in the List
  • SelectedIndex - Gets / Sets the Index of the Row currently selected
  • Text - Gets / Sets the Text from/to the TextBox part of the component

Events

  • ItemSelected - Occurs when a Row is Selected / programmatically Unselected
  • DropDownChanged - Occurs when the List is Opened/Closed

Methods

  • AddColumn - Creates a new Column (with 1 required and 13 optional parameters)
    Syntax:
    AddColumn(HeaderText As String,
        [Width As Integer = 80],
        [Align As System.Windows.Forms.HorizontalAlignment = HorizontalAlignment.Left],
        [DataType As ExCB.ExCB.DataType = ExCB.ExCB.DataType._Text],
        [Format As String = Nothing],
        [ForeColor As System.Drawing.Color = Nothing], '(VS2012)
        [BackColor As System.Drawing.Color = Nothing], '(VS2012)
        [ImgWidth As Integer = 0],
        [ImgHeight As Integer = 0],
        [SizeMode As ExCB.ExCB.SizeMode = ExCB.ExCB.SizeMode._Stretch],
        [Resizable As Boolean = True],
        [Reordable As Boolean = True],
        [Sortable As Boolean = True],
        [ArrowOnRight As Boolean = False])
  • AddRow - Adds a Row (Item) to the ListView (sends a String or Object Array)
  • ARGB - Converts a Color to its Integer value
  • Clear - Deletes all Rows of the List (including Embedded Controls), optionally all Columns
  • RowSelect - Selects a Row, giving a Value and a Column Index, optionally returning another subitem
  • GetImage - Retrieves the Image at the specified Index within the Component's array

History

03.Jun.2014 - First posted

05.Jun.2014 - Added Last Updates 1. and 2. to See Documentation and Examples

11.Jun.2014 - Added Last Updates 3. and 4. to See Documentation and Examples

05.Dec.2014 - Added Last Updates 5. to See Documentation and Examples

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Avelino Ferreira
Retired
Portugal Portugal
Working on computers since Mar,6 1969
 
Languages: RPN, Fortran, COBOL, Univac 1100 Meta-assembler, Basic, Z80 Assembly, 8086 Assembly, IBM Assembler (360/370, 38xx, 43xx), ANSI C, SQL, Visual Basic, VBA, VB.NET
 
Actually retired, but still developing (for pleasure).

Comments and Discussions

 
Questiontoo young to retire Pinmemberzpaulo_carraca9-Dec-14 6:50 
AnswerRe: too young to retire PinmemberAvelino Ferreira9-Dec-14 7:56 
QuestionTwo questions (maybe a challenge?) PinmemberL.Botello1-Dec-14 5:35 
AnswerRe: Two questions (maybe a challenge?) PinmemberAvelino Ferreira5-Dec-14 6:25 
GeneralRe: Two questions (maybe a challenge?) PinmemberL.Botello8-Dec-14 5:49 
GeneralMy vote of 5 PinmemberJuan R. Huertas21-Aug-14 23:05 
GeneralRe: My vote of 5 PinmemberAvelino Ferreira22-Aug-14 5:44 
GeneralMy opinion PinmemberRoberto Pasquali28-Jul-14 3:05 
GeneralRe: My opinion PinmemberAvelino Ferreira28-Jul-14 4:07 
GeneralMy vote of 5 PinprofessionalMihai MOGA20-Jul-14 5:37 
GeneralRe: My vote of 5 PinmemberAvelino Ferreira20-Jul-14 13:36 
Questionvery nice PinprofessionalBillW3316-Jul-14 10:40 
AnswerRe: very nice PinmemberAvelino Ferreira16-Jul-14 12:54 
GeneralRe: very nice PinprofessionalBillW3317-Jul-14 8:33 
QuestionGreat control PinmemberHeriberto Lugo13-Jul-14 7:45 
Great control. would've been nice if you explained what you were doing, how & why.. Nice job though. Thumbs Up | :thumbsup:
AnswerRe: Great control PinmemberAvelino Ferreira15-Jul-14 9:58 
GeneralRe: Great control PinmemberHeriberto Lugo15-Jul-14 14:33 
SuggestionSome suggestions PinmemberMember 106300083-Jul-14 8:06 
GeneralRe: Some suggestions PinmemberAvelino Ferreira15-Jul-14 9:53 
GeneralRe: Some suggestions PinmemberMember 1063000816-Jul-14 2:08 
QuestionSome suggestion PinmemberTridip Bhattacharjee12-Jun-14 21:57 
AnswerRe: Some suggestion PinmemberAvelino Ferreira13-Jun-14 5:05 
AnswerRe: Some suggestion PinmemberHeriberto Lugo13-Jul-14 7:52 
GeneralExcellent! Finally, the Listview's Column Header Height handling explained! PinmemberL.Botello8-Jun-14 4:41 
GeneralRe: Excellent! Finally, the Listview's Column Header Height handling explained! PinmemberAvelino Ferreira9-Jun-14 1:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.141220.1 | Last Updated 5 Dec 2014
Article Copyright 2014 by Avelino Ferreira
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid