List Box CellClick Question

Hi,

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

Thanks!

I haven’t tried yet,

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

Torsten excellent Idea! I will try this now. Thank you!!

So far its not working as the Change event doesn’t have Row nor Return value, but I am trying the concept in the CellClick event.

With this code it works

i means row
and ListBox1 is your listbox (me)
and you are right the change event doesn’t has a return value

For i as integer=0 to ListBox1.ListCount - 1
if ListBox1.Selected( i ) then
if ListBox1(i,1) = "Working" then ListBox1.Selected(i) = false
end if
Next

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.

Thank you for helping!

[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]

[quote=94844:@Torsten Gaidies]Yes, there is a highlighting for a short time,

it would be nice if we could fetch a event directly before the rows are highlighted. If you have a solution for it, I’m interessted in it.[/quote]

See me post above

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.

Karen,
that works fine now.

Thank you Torsten and Karen!