I have a need to prevent a user from clicking a Listbox Row. I am accomplishing this by adding the following code in the CellClick event.
// Don't Allow Users to Select the Working/Busy ICP's
if Me.CellTag(row,1) = "Working" Then
Return True
end if
My issues comes in when I enable Multiple Selections. If you try to single click on that row individually it works well. If you include that row in a multiple selection it ignores the return true and is selected. Any idea on how to also prevent this Row from being selected within a multi-selection?
** Also to add the cells in this row are not editable
but if you use the listbox change event, you can go througn the selected rows and unselect the wanted one.
For i as integer=0 to ListBox1.ListCount - 1 //Indexes are zero-based
if ListBox1.Selected( i ) then
if Me.CellTag(row,1) = “Working” then ListBox1.Selected(i) = false
end if
Next
return true
For i as integer=0 to ListBox1.ListCount - 1
if ListBox1.Selected( i ) then
if ListBox1.celltag(i,1) = “Working” then ListBox1.Selected(i) = false
end if
Next
Torsten it works, but it still highlights the row and quickly then de-selects it. I need it to not highlight at all, but will rethink this as I just may slightly change it so this isn’t an issue.
[quote=94842:@Mike Cotrone]Torsten it works, but it still highlights the row and quickly then de-selects it. I need it to not highlight at all, but will rethink this as I just may slightly change it so this isn’t an issue.
Thank you for helping![/quote]
In MouseDown do:
[code]Dim Row as Integer = me.RowFromXY(x,y)
If Row >= 0 AND row < me.ListCount AND Me.CellTag(row,1) = “Working” Then
Return True
end if[/code]
Hi,
thats ok when only the meant row is selected. When you for example select the first row, hold the shift key down and than select the last row, the selection is there (if the meant row is not the first or last one).
[quote=94846:@Torsten Gaidies]Hi,
thats ok when only the meant row is selected. When you for example select the first row, hold the shift key down and than select the last row, the selection is there (if the meant row is not the first or last one).
[/quote]
Then fake it in CellBackgroundPaint and CellTextPaint and do “Working” CellTag checks when you use the selected rows.
In CellBackgroundPaint:
If row < me.Listcount And Me.CellTag(row,1) = "Working" Then
g.forecolor = &cFFFFFF00
g.fillRect 0,0, g.width, g.height
Return True
End if
In CellTextPaint:
If Me.CellTag(row,1) = "Working" Then g.forecolor = &c00000000
Now rows with a celltag in column 1 of “Working” will NEVER look highlighted and you can check the Tag in code when operating on selected rows.