Click here to Skip to main content
15,897,371 members
Articles / Web Development / HTML

ExCB - Extended Multi Column ComboBox

Rate me:
Please Sign up or sign in to vote.
4.77/5 (31 votes)
21 Mar 2016CPOL6 min read 78.7K   3.6K   43  
Presenting an easy-to-use, flexible, filterable ComboBox, managing various data types (including images), also sortable, resizable and reordable columns
Public Class Form2

    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Players_Column_Definitions()
        Read_Players()

    End Sub

#Region "Players"

    Private Sub Players_Column_Definitions()

        ' Defining Columns for Excb1:
        ' Usage:
        ' Excb1.AddColumn(HeaderText as String, [Width=80], [Align=Left], [DataType=_Text], [Format=Nothing],  
        '               [ForeColor=Nothing], [BackColor=Nothing], [ImgWidth=0], [ImgHeight=0]), [SizeMode=_Stretch], 
        '               [Resizable=True], [Reordable=True], [Sortable=True], [ArrowOnRight=False]

        ' Column 0: Player ID, not visible (width 0), numeric, not resizable, not reordable, not sortable
        Excb1.AddColumn("ID", 0, , ExCB.ExCB.DataType._Numeric, , , , , , False, False, False)

        ' Column 1: European Player?, width 90, align center, boolean, forecolor Blue, backcolor ARGB(255, 242, 251), 
        '           checkbox(image)Width 30, checkbox(image)Height 16
        Excb1.AddColumn("European", 90, HorizontalAlignment.Center, ExCB.ExCB.DataType._LogicImg, , _
                      Color.Blue, Color.FromArgb(255, 242, 251), 30, 16)

        ' Column 2: Rank, width 60, align center, numeric, default colors, not reordable, sort arrow on right
        Excb1.AddColumn("Rank", 60, HorizontalAlignment.Center, ExCB.ExCB.DataType._Numeric, , , , , , , , False, , True)

        ' Column 3: Name, width 130, [align left], string, forecolor DarkBlue, backcolor ARGB(255,253,233)
        Excb1.AddColumn("Name", 130, , , , Color.DarkBlue, Color.FromArgb(255, 253, 233))

        ' Column 4: Country(of player), width 100, align center, image, backcolor ARGB(231, 255, 227), 
        '           imageWidth 90, imageHeight 60, [SizeMode Stretch], sort arrow on right
        Excb1.AddColumn("◄ Country", 100, HorizontalAlignment.Center, ExCB.ExCB.DataType._Image, , , _
                      Color.FromArgb(231, 255, 227), 90, 60, , , , , True)

        ' Column 5: Photo, width 120, align center, image, backcolor ARGB(231, 255, 227), 
        '           imageWidth 111, imageHeight 148, image SizeMode Zoom
        Excb1.AddColumn("Photo", 120, HorizontalAlignment.Center, ExCB.ExCB.DataType._Image, , , _
                      Color.FromArgb(255, 253, 233), 111, 148, ExCB.ExCB.SizeMode._Zoom)

        ' Column 6: Birth Date, width 90, align center, date, display format "dd.MMM.yyyy", default colors
        Excb1.AddColumn("Birth Date", 90, HorizontalAlignment.Center, ExCB.ExCB.DataType._Date, "dd.MMM.yyyy")

        ' Column 7: Actual age, width 55, align center, numeric, forecolor White, backcolor DarkBlue
        Excb1.AddColumn("Age", 55, HorizontalAlignment.Center, ExCB.ExCB.DataType._Numeric, , _
                      Color.White, Color.DarkBlue)

        ' Column 8: Team, width 160, align left, string, backcolor ARGB(242, 248, 255)
        Excb1.AddColumn("Team", 160, , , , Color.Maroon, Color.FromArgb(242, 248, 255))

        ' Column 9: Country(of team), width 90, align center, image, backcolor ARGB(255, 245, 255), 
        '           imageWidth 45, imageHeight 30, [SizeMode Stretch], sort arrow on right
        Excb1.AddColumn("◄ Country", 90, HorizontalAlignment.Center, ExCB.ExCB.DataType._Image, , , _
                     Color.FromArgb(255, 245, 255), 45, 30, , , , , True)

        'Excb1.DisplayColumn = 3     ' Column to display when selected (Name)

        ' Sum of widths = 895. 

    End Sub

    Private Sub Read_Players()

        ' Usually, data is read from a database, using a DataReader (DR), like:
        ' While DR.Read()
        '   ... read each record ...
        '       ' At least in VS2012, this syntax is allowed:
        '   Excb1.AddRow({DR(0), DR(1), DR(2), Calc_Actual_Age(DR(2)), DR(3), DR(4)})
        '       ' meaning:
        '   Excb1.AddRow({P1_ID, P1_Rank, P1_Birth, Calc_Actual_Age(P1_Birth), P1_Name, P1_Team})
        ' End While

        ' but for now:

        Dim ImagesPath As String = Application.StartupPath & "\Images\"

        Dim Record(9) As String
        ' Sending at least one image, the Array must be defined as Object
        ' Otherwise, using only folder/file Paths, the Array can be defined
        ' as String, for better performance (this case)

        Record(0) = 456
        Record(1) = True
        Record(2) = 1
        Record(3) = "Cristiano Ronaldo"
        Record(4) = ImagesPath & "Portugal.PNG"
        Record(5) = ImagesPath & "Ronaldo.PNG"
        Record(6) = DateSerial(1985, 2, 5)
        Record(7) = Calc_Actual_Age(Record(6))
        Record(8) = "Real Madrid C.F."
        Record(9) = ImagesPath & "Spain.PNG"
        Excb1.AddRow(Record)

        Record(0) = 789
        Record(1) = False
        Record(2) = 2
        Record(3) = "Lionel Messi"
        Record(4) = ImagesPath & "Argentina.PNG"
        Record(5) = ImagesPath & "Messi.PNG"
        Record(6) = DateSerial(1987, 6, 24)
        Record(7) = Calc_Actual_Age(Record(6))
        Record(8) = "F. C. Barcelona"
        Record(9) = ImagesPath & "Spain.PNG"
        Excb1.AddRow(Record)

        Record(0) = 123
        Record(1) = True
        Record(2) = 3
        Record(3) = "Frank Ribéry"
        Record(4) = ImagesPath & "France.PNG"
        Record(5) = ImagesPath & "Ribery.PNG"
        Record(6) = DateSerial(1983, 4, 7)
        Record(7) = Calc_Actual_Age(Record(6))
        Record(8) = "F. C. Bayern Munchen"
        Record(9) = ImagesPath & "Germany.PNG"
        Excb1.AddRow(Record)

    End Sub

#End Region

End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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


Written By
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), Clipper, ANSI C, SQL, Visual Basic, VBA, VB.NET
Lately, some HTML, JavaScript, C#
Actually retired, but still developing (for pleasure).

Comments and Discussions