PC Review


Reply
Thread Tools Rate Thread

display problem with listbox

 
 
Luke Alcatel
Guest
Posts: n/a
 
      3rd Jul 2008
I use an MSForms ListBox and I've implemented functions to sort the rows
according to column values when I click on a column header. I have found
that after sorting, the displayed rows are in correct sort order but rows
that were scrolled out of view often are not, i.e. those rows are not
repainted. I tried a repaint in the scroll event handler but this did not
correct the problem. How can I force the needed graphical rendering update?

Luke


 
Reply With Quote
 
 
 
 
JLGWhiz
Guest
Posts: n/a
 
      3rd Jul 2008
Have you actually isolated the problem to being a graphic repaint problem and
not a problem with the function to sort the data? It is difficult to analyze
without seeing the relative code.

"Luke Alcatel" wrote:

> I use an MSForms ListBox and I've implemented functions to sort the rows
> according to column values when I click on a column header. I have found
> that after sorting, the displayed rows are in correct sort order but rows
> that were scrolled out of view often are not, i.e. those rows are not
> repainted. I tried a repaint in the scroll event handler but this did not
> correct the problem. How can I force the needed graphical rendering update?
>
> Luke
>
>
>

 
Reply With Quote
 
Luke Alcatel
Guest
Posts: n/a
 
      3rd Jul 2008
When I make the ListBox unusually large such that there is no scrolling for
a typical set of data this problem does not occur. I attached the code
below although I haven't included my bubbleSort which I can provide if
anyone really wants it. Suffice to say that the same sort has been used in
other programs and even in this program there is no problem when the ListBox
is large.

Luke

'Sort the rows of ListBox lbox using the entries in column number col
'(zero-based) as a key. labels is the column headings, the label on
'which the table is sorted is colored blue, others are black. The sort
'algorithm understands lexical and non-negative numeric ordering.
Public Sub listBoxSort(lbox As MSForms.ListBox, _
labels() As MSForms.label, ByVal col As Integer)

Dim ndx As Integer, a() As String, p() As String, val As String
Dim walk As Integer, place As Integer, v() As String

If col < 0 Or col >= lbox.ColumnCount Then
Exit Sub
End If
'extract keys and table data
ReDim a(lbox.ListCount - 1)
ReDim v(lbox.ListCount - 1)
For ndx = 0 To lbox.ListCount - 1
val = lbox.list(ndx, col)
If IsNumeric(val) Then
val = Format(val, "0000000000000000")
Else
val = val & left(" ", 16 - Len(val))
End If
a(ndx) = val & vbTab & ndx
v(ndx) = lbox.list(ndx, 0)
For walk = 1 To lbox.ColumnCount - 1
v(ndx) = v(ndx) & vbTab & lbox.list(ndx, walk)
Next walk
Next ndx
'sort keys and pointers to data
bubbleSort a, lbox.ListCount, 0
're-insert sorted table data
For ndx = 0 To UBound(a)
p = Split(a(ndx), vbTab)
place = p(1)
p = Split(v(place), vbTab)
For walk = 0 To UBound(p)
lbox.list(ndx, walk) = p(walk)
Next walk
Next ndx
'highlight the label for column used as sort keys
For ndx = 0 To UBound(labels)
If ndx = col Then
labels(ndx).ForeColor = RGB(0, 0, 255)
Else
labels(ndx).ForeColor = &H80000012
End If
Next ndx
End Sub

"JLGWhiz" <(E-Mail Removed)> wrote in message
news:06D03F97-5383-4860-91E9-(E-Mail Removed)...
> Have you actually isolated the problem to being a graphic repaint problem

and
> not a problem with the function to sort the data? It is difficult to

analyze
> without seeing the relative code.
>
> "Luke Alcatel" wrote:
>
> > I use an MSForms ListBox and I've implemented functions to sort the rows
> > according to column values when I click on a column header. I have

found
> > that after sorting, the displayed rows are in correct sort order but

rows
> > that were scrolled out of view often are not, i.e. those rows are not
> > repainted. I tried a repaint in the scroll event handler but this did

not
> > correct the problem. How can I force the needed graphical rendering

update?
> >
> > Luke
> >
> >
> >



 
Reply With Quote
 
Luke Alcatel
Guest
Posts: n/a
 
      3rd Jul 2008
I have an indirect solution. Before rewriting each row of the sorted
ListBox I set the TopIndex property to that row number. This insures that
when a row is updated it is visible. There is the somewhat weird effect of
the listbox scrolling around by itself but think of it as a progress bar
:-). The solution demonstrates that the core issue really is repaint. I'm
using Excel 2000 so it's possible that this problem does not occur in later
versions.

Luke

"Luke Alcatel" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> When I make the ListBox unusually large such that there is no scrolling

for
> a typical set of data this problem does not occur. I attached the code
> below although I haven't included my bubbleSort which I can provide if
> anyone really wants it. Suffice to say that the same sort has been used

in
> other programs and even in this program there is no problem when the

ListBox
> is large.
>
> Luke
>
> 'Sort the rows of ListBox lbox using the entries in column number col
> '(zero-based) as a key. labels is the column headings, the label on
> 'which the table is sorted is colored blue, others are black. The sort
> 'algorithm understands lexical and non-negative numeric ordering.
> Public Sub listBoxSort(lbox As MSForms.ListBox, _
> labels() As MSForms.label, ByVal col As Integer)
>
> Dim ndx As Integer, a() As String, p() As String, val As String
> Dim walk As Integer, place As Integer, v() As String
>
> If col < 0 Or col >= lbox.ColumnCount Then
> Exit Sub
> End If
> 'extract keys and table data
> ReDim a(lbox.ListCount - 1)
> ReDim v(lbox.ListCount - 1)
> For ndx = 0 To lbox.ListCount - 1
> val = lbox.list(ndx, col)
> If IsNumeric(val) Then
> val = Format(val, "0000000000000000")
> Else
> val = val & left(" ", 16 - Len(val))
> End If
> a(ndx) = val & vbTab & ndx
> v(ndx) = lbox.list(ndx, 0)
> For walk = 1 To lbox.ColumnCount - 1
> v(ndx) = v(ndx) & vbTab & lbox.list(ndx, walk)
> Next walk
> Next ndx
> 'sort keys and pointers to data
> bubbleSort a, lbox.ListCount, 0
> 're-insert sorted table data
> For ndx = 0 To UBound(a)
> p = Split(a(ndx), vbTab)
> place = p(1)
> p = Split(v(place), vbTab)
> For walk = 0 To UBound(p)
> lbox.list(ndx, walk) = p(walk)
> Next walk
> Next ndx
> 'highlight the label for column used as sort keys
> For ndx = 0 To UBound(labels)
> If ndx = col Then
> labels(ndx).ForeColor = RGB(0, 0, 255)
> Else
> labels(ndx).ForeColor = &H80000012
> End If
> Next ndx
> End Sub
>
> "JLGWhiz" <(E-Mail Removed)> wrote in message
> news:06D03F97-5383-4860-91E9-(E-Mail Removed)...
> > Have you actually isolated the problem to being a graphic repaint

problem
> and
> > not a problem with the function to sort the data? It is difficult to

> analyze
> > without seeing the relative code.
> >
> > "Luke Alcatel" wrote:
> >
> > > I use an MSForms ListBox and I've implemented functions to sort the

rows
> > > according to column values when I click on a column header. I have

> found
> > > that after sorting, the displayed rows are in correct sort order but

> rows
> > > that were scrolled out of view often are not, i.e. those rows are not
> > > repainted. I tried a repaint in the scroll event handler but this did

> not
> > > correct the problem. How can I force the needed graphical rendering

> update?
> > >
> > > Luke
> > >
> > >
> > >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Microsoft Access ListBox display problem peli45 Microsoft Access VBA Modules 0 28th Aug 2009 02:14 PM
Problem display RTF filed on listbox SF Microsoft Access 1 17th Jun 2009 05:19 AM
Incremental User input into Listbox display problem... Regnab Microsoft Access Queries 3 12th Jul 2006 01:10 PM
Listbox data display problem Henry Microsoft Excel Programming 7 11th Nov 2005 11:59 PM
ListBox Display Problem DS Microsoft Access 3 8th Jul 2005 10:22 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:47 PM.