ListBox: Clear the selected Column

In a ListBox, I want to clear the selected Column (highlighted Heading). I tried without success:

[code] LB.ColumnsortDirection(0) = ListBox.SortNone
LB.SortedColumn = 0
LB.Sort
// LB.PressHeader(-1) // Out of Bounds error… *
Self.Focus = Nil

Return True[/code]

Idea ?

  • If I set the Column value to 0 (instead of -1), the column 0 “sort” is set, but the highlight is still where it was earlier…

BTW: do you know how to get the effect you can see in the following image ? (show in OS X, but exists also in Windows).

me.headingIndex = 0 ?

I think outside of that you will need to add a column set it’s width to zero and then use that one so for a 3 column listbox where the 3rd has a width of zero

Function HeaderPressed As Boolean
If column = 1 then me.headingIndex = me.columncount -1

Oh this is a goofy one, I’ve got a snippet here I got from Dave a while back.

// No longer sorted, deselect col header. me.SortedColumn = -1 // this clears the sorting internally me.HasHeading = false // these two lines redraw the listbox header me.HasHeading = true

seems like a bug that setting it to -1 doesn’t clear it visually

Clearing the column header selection highlight for a listbox has ALWAYS been a black art going back to when i started (RB3)

Reading the list box docs about setting it to -1 might lead you to, I think quite reasonably, expect that there would be no column being sorted on hence no header that suggests there IS one.

EDIT : a search of feedback found a couple related bug reports (not sure why one was an inquiry so I changed it to a bug report today)
feedback://showreport?report_id=15616
feedback://showreport?report_id=18623

Hi,

Regarding the question which I have cited above, if you want to know how to have the lines in different colors, you can try doing this:

In your listbox, there is an event handler called CellBackgroundPaint. Do this:

If row < Listbox1.ListCount-1 Then
If row Mod 2 = 0 Then
g.ForeColor = RGB(255,0,0)
Else
g.ForeColor = RGB(0,0,255)
End If
g.FillRect 0,0,g.Width,g.Height
End If

You have to select your own colors if you don’t like those red and blue.

So, it may works before OR it’s my memory that is really bad. I recall (?) we had a solution sometimes ago, but due to a change (a deprecated instruction), it changed since. That is why I tested what I can and failed.

Now, at no time I was feeling that could be a bug or a miss !!!

Thank you with all the people having answered!

Reading your answer, Norman, lead me to think at:

Remove the Heading when asked to clear previous contents,
Set the Headings Back at data loading time.

This may look strange to the user (a flicker ?), but it achieve the trick:
no selected column at new data loading time
keep the data at the load time flow
at least, do not fool the user with a sorted column interface and no sorted data below.

Note: I’m typing this mail sitting in my car nears a free wifi hot spot (I’ve made a simple error: I goes out of my home one hour early (mistake while reading the hour ! And so I cannot test the suggestion(s).
;-:slight_smile:

Thanks all.

I tested the idea: set HasHeading to False (so no Headin column pressed is shown) and back to True at Loading data time:

Works fine, no flickering on OS X. It is a workaround !

[quote=127726:@Emile Schwarz]I tested the idea: set HasHeading to False (so no Headin column pressed is shown) and back to True at Loading data time:

Works fine, no flickering on OS X. It is a workaround ![/quote]
That’s what Tim wrote. If helps if you read the answers to your questions :wink:

Markus,

thanks for the answer: I do not noticed that, I only read the first line of code (I think).

Now, I checked it and… this works !

LB.SortedColumn = -1 LB.HasHeading = False LB.HasHeading = True

Thanks all !

The two HasHeading lines alone does not do the trick (I just checked) and I suppose that SortedColumn = -1 does not do it too (I certainly tried that before asking for help here).

And what’s not working with the HeadingIndex?

Works fine on Windows.

Actually setting it -1 works just fine just had to play with a little

The docs says: [quote]This property is obsolete[/quote].

I do not have bad feelings against HeadingIndex (nor anyone else).

;-:slight_smile:

Listbox1.SortedColumn = -1 does not remove the selection from the header like HeadingIndex does. I guess that’s a bug …?

Thanks @Tim Parnell! That solved my question… :slight_smile:

For those who need the API 2.0 edition:

me.SortingColumn = -1 me.HasHeader = False me.HasHeader = True