Can we do column selection in listbox?

Hi,

Can we do column selection in listbox?
I need to allow user to select column values in listbox.

as a built in feature? no
as a coded function based on the CELLPAINT type events… sure … but it up to you

Can you let me know if there is any example on that matter?

Add these to your project:
ListBox
CellSelected as boolean = false
SelectedColumn as integer = -1

Set ColumnCount of ListBox1 to 5
Set “HadHeading” f ListBox1 to ON

Add These events to the ListBox1:

Sub Open()
for i as integer = 0 to 50
me.AddRow(“1”,“2”,“3”,“4”,“5”)
next
End Sub

Function HeaderPressed(column as Integer) As Boolean
if me.ColumnsortDirection(column) = ListBox.SortAscending then
CellSelected = true
else
CellSelected = false
end if

SelectedColumn = column

return false
End Function

Function CellBackgroundPaint(g As Graphics, row As Integer, column As Integer) As Boolean
if CellSelected then
if column = SelectedColumn then
g.ForeColor = &cf3f6fA
g.FillRect(0, 0, g.Width, g.Height)
end if
end if

return true
End Function

Run your project, click on any column of ListBox1 and the complete column will be displayed in light blue color.

Thank you Horst !

I added yesterday Copy Column and Paste Column. I do not know if I will use your code, but I find it appearance interesting !