Sortable WebListbox Kinda...

I have a sortable weblistbox that sorts by clicking on the column headers. It works well but has restrictions. This is for a subclassed weblistbox

Here is the overridden MouseDown Event

[code]x = x - (Session.CurrentPage.Width - self.Parent.Width) / 2
y = y - (Session.CurrentPage.Height - self.Parent.Height) / 2
//^I always embed my custom weblistbox in a WebContainer. I need this adjustment if it happens to be in a WebDialog that is centered

if y < 24 then
//Determine column
dim c as integer = -1
dim w as integer
For i as integer = 0 to me.ColumnCount - 1
dim s as string = me.ColumnWidth(i)
dim cs as integer = val(s)
if w + cs < x then
w = w + cs
c = i
if c <> -1 then
RaiseEvent SortColumn© //You’ll need to implement this
RaiseEvent MouseDown(x,y,details) //You’ll need to add this[/code]

For my implementation I have a SortColumn which alter the SQL query and redisplay the listbox with the ordered fields. It also changes the column headers so that the sorted column either shows " ?" or " ?" at the end of it.

This works… mostly. It only works with explicitly defined column sizes (in other words the exact pixel size, nothing like “2*”).
It also only works if the Weblistbox has not been scrolled horizontally.

I would like to make this solution more robust. Does anyone know a good way to determine the column from a X coordinate when there are dynamically sized column widths? Also does anyone know a way that I can track the value of the horizontal scroll bar?