Border around only the selected listbox row?

Hi,
I have the following code which puts a border around row 1 column 1 of my listbox.
What I am trying to do is put the border around column 1 of the selected row only.

Could someone please advise me how I modify my code below, to achieve this.

If Me.Selected(row) Then me.CellBorderBottom(1, 1) = ListBox.BorderThinSolid me.CellBorderTop(1,1) = ListBox.BorderThinSolid End If

Thank you all in advance.

If Me.Selected(row) Then me.CellBorderBottom(row, 1) = ListBox.BorderThinSolid me.CellBorderTop(row,1) = ListBox.BorderThinSolid End If

Duhhhh - been a long day :slight_smile:
Unfortunately, that is far too buggy. When I left click a row, then right click another, I end up with 2 rows highlighted :frowning:

you need to set the others to NOT have a border when you change the selection

I tried that :frowning:
It acts erratic - sometimes it works, other times it doesn’t ??

Yep, Norman…maybe do a for…next loop and set the others to not have a border, checking in the loop to see if the current number in the loop matches the listindex and skip it, then do an listbox.invalidate?

Borders are often too flakey for dealing with UI events involving the Keyboard and Mouse. I have found it is much easier and cleaner to do stuff like this in the CellBackgroundPaint event with graphics object.

I handle such things in the CellBackgroundPaint event handler, for example:

[code]Function CellBackgroundPaint(g As Graphics, row As Integer, column As Integer) As Boolean
// Paint even rows, not selected
If row Mod 2=0 And Not Me.selected(row) Then
g.foreColor=&cECF3FE // light blue
g.fillrect 0,0,g.width,g.height

If column = 6 Then
  g.foreColor=&cFFFF0000  // column 6 yellow
  g.fillrect 0,0,g.width,g.height
End If

If column = 7 Then
  g.foreColor=&cE6E6E600   // column 7 gray
  g.fillrect 0,0,g.width,g.height
End If

// Paint odd rows, not selected

Elseif row Mod 2<>0 And Not Me.selected(row) Then
g.foreColor=&cFFFFFF // white
g.fillrect 0,0,g.width,g.height

If column = 6 Then
  g.foreColor=&cFFFF0000  // column 6 yellow
  g.fillrect 0,0,g.width,g.height
End If

If column = 7 Then
  g.foreColor=&cE6E6E600  // column 7 gray
  g.fillrect 0,0,g.width,g.height
End If


// When selected, then draw a top and bottom border

Elseif Me.selected(row) Then

If column<6 Then
  ' im.gradient(g,Me)
  g.foreColor=&cFFFFFF00  // white
  g.fillrect 0,0,g.width,g.height
  
  g.foreColor=&c00000000
  g.DrawLine 0,0,g.width,0  // border top
  g.DrawLine 0,g.Height-1,g.width,g.Height-1  // border bottom
Else
  
  If column = 6 Then
    g.foreColor=&cFFFF0000
    g.fillrect 0,0,g.width,g.height
    
    g.foreColor=&c00000000
    g.DrawLine 0,0,g.width,0
    g.DrawLine 0,g.Height-1,g.width,g.Height-1
    
  End If
  
  If column=7 Then
    g.foreColor=&cE6E6E600
    g.fillrect 0,0,g.width,g.height
    
    g.foreColor=&c00000000
    g.DrawLine 0,0,g.width,0
    g.DrawLine 0,g.Height-1,g.width,g.Height-1
    
  End If
End If

End If

Return True
End Function
[/code]

And the code above produces a list looking like this:

Nothing to do with border, but I find interesting the use of apostrophe as thousand separator in your screen grab. In the US that would be coma.

Thank you very much - that helped!

Yes, what you see is a screenshot from a Swiss-French system. On a US-English one the same data presents like this:

[quote=139524:@Oliver Osswald]Yes, what you see is a screenshot from a Swiss-French system. On a US-English one the same data presents like this:

[/quote]

Interesting. In France, decimal is coma and thousand is space.

LIke this, I guess:

[quote=139535:@Oliver Osswald]LIke this, I guess:

[/quote]

Exactly.

That’s the decimal point. I thought he was talking about the thousand’s separator? Is that how it is shown with an apostrophe?

France decimal : coma ; thousand : space
Swiss French decimal : dot ; thousand : apostrophe
US decimal : dot ; thousand : coma

gotta love having so many standards to choose from :stuck_out_tongue: