• Welcome to PlanetSquires Forums.
 

WinFBE Suite 2.0.5 - ListView

Started by SeaVipe, February 20, 2020, 01:06:38 PM

Previous topic - Next topic

SeaVipe

Hi Paul,
My compiled app will crash when the following code is called on a previously populated ListView (it works fine on a ListView that hasn't yet had Rows added):

ListView1.BeginUpdate
ListView1.Items.Clear

To solve this I reversed the order of the commands:


ListView1.Items.Clear
ListView1.BeginUpdate

However, if the same code (with the above fix) is compiled with 2.0.3, that app will now crash were it wouldn't prior to reversing .Clear and .BeginUpdate.
Clive Richey

Paul Squires

Thanks Clive - I have been able to replicate the crash. I will now work on a fix.
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Paul Squires

Okay, this is now fixed. Had to ensure that ListView_SetItemCountEx was called prior to turning the control's WM_REDRAW back on regardless of whether the BeginUpdate was active or not.
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

SeaVipe

Thanks, Paul. In the interim, I'll try that too.
Clive Richey

Paul Squires

This is what the code for wfxListViewItemsCollection.Clear located in wfxListView.inc now looks like:


function wfxListViewItemsCollection.Clear() as long
   ' Deallocate elements in the Items collection.
   ' In order to speed the deallocations, we first loop through
   ' the collection and deallocate the ListViewItems. We then call
   ' the LList's method Clear to quickly deallocate the list nodes
   ' and erase the list.
   ' Disabling drawing updates until all of the nodes are deleted,
   ' otherwise we could get a GPF on a redraw while the node is being deleted.
   SendMessage( this.hWindow, WM_SETREDRAW, false, 0 )
   dim pNode as wfxLListNode ptr
   for i as long = 0 to _Collection.Size - 1
      pNode = _Collection.get_index(i)
      ' Delete ListViewItem fires destructor that deletes any subitems
      Delete cast(wfxListViewItem ptr, pNode->pData)
   next
   _Collection.Clear

   If this.hWindow Then
      ListView_SetItemCountEx( this.hWindow, this.Count, LVSICF_NOINVALIDATEALL or LVSICF_NOSCROLL)
      if this.UpdateFlag = false then AfxRedrawWindow(this.hWindow)
   end if
   SendMessage( this.hWindow, WM_SETREDRAW, true, 0 )
   function = 0
END FUNCTION

Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Paul Squires

Also, luckily, during testing of that problem in the prior posts, I was able to notice the issue whereby Frame controls would "disappear". I was able to track it down to situation where a modal dialog is displayed during the Form's Load event. I added code to the wfxForm.inc file to redraw any Frame controls prior to the exiting of the Form creation code (wfxForm.CreateFormInternal). It seems to work well. Maybe there are other cases whereby Frame controls disappear and if I can identify such cases then I will fix those as well.
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

SeaVipe

Hi Paul,
When replacing or adding the text of a ListView control, I call the Clear command just prior to .BeginUpdate and Items.Add and SubItems.Add.

It appears as though the .SelectedItem then gets set to 0 so that when the ListView is repopulated with new data, the Highlighted row is moved to 0. This in and of itself isn't a real problem except that the Highlight colours are Windows default colours that override any colouring that row 0 may have.
A simple workaround is to save the row to a variable prior to the Clear command and then set the row back to that variable after .EndUpdate. This too is okay, but there is still the Windows default .SelectedItem colours issue (my PC is set to white FG on a blue BG).
Is there a way to not change the highlighted row colouring or Colour just the grid lines or the ListView BG colour associated with that row or perhaps colour settings similar to a ListBox?
Thanks for all your hard work on WinFBE, Paul, it really is working great!
Clive Richey

Paul Squires

Hi Clive, I am not 100% sure that I understand the problem but your approach should work if you manipulate the SelectedIndex property of the ListView.

Save the current selected index.
Clear the ListView (this resets the SelectedIndex property to -1)
Load the ListView
Set the SelectedIndex to the previously saved value.

frmMain.ListView1.SelectedIndex = nSavedIndex

There is not much we can do about the FG/BG colors of the selected row. It uses the system colors. This is by design for a ListView and there is no easy way to workaround that because I am using CustomDraw for ListViews (unlike ListBoxes where I am using OwnerDraw and draw everything myself). Do a google search for setting a listview selected item colors and you'll see what I mean. Other than drawing the entire items myself during the custom drawing messages, there is nothing obvious that I can do to change the colors.
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

SeaVipe

#8
Thanks, Paul.
OwnerDraw is not a simple solution...
Clive Richey