PlanetSquires Forums

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: WinFBE Suite 2.0.5 - ListView  (Read 286 times)

SeaVipe

  • Senior Member
  • ***
  • Posts: 355
  • Windows 10
WinFBE Suite 2.0.5 - ListView
« on: February 20, 2020, 01:06:38 PM »

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):
Code: [Select]
ListView1.BeginUpdate
ListView1.Items.Clear
To solve this I reversed the order of the commands:

Code: [Select]
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.
Logged
Clive Richey
*“You Either Have To Be Part Of The Solution, Or You’re Going To Be Part The Problem.” Eldridge Cleaver.
#StaySafe, Always  Keep A Safe #SocialDistance, #WashYourHands Often and please, #StayHome!

Paul Squires

  • Administrator
  • Guru Member
  • *****
  • Posts: 9202
  • Windows 10
    • PlanetSquires Software
Re: WinFBE Suite 2.0.5 - ListView
« Reply #1 on: February 20, 2020, 02:06:06 PM »

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

Paul Squires

  • Administrator
  • Guru Member
  • *****
  • Posts: 9202
  • Windows 10
    • PlanetSquires Software
Re: WinFBE Suite 2.0.5 - ListView
« Reply #2 on: February 20, 2020, 02:23:39 PM »

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.
Logged
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

SeaVipe

  • Senior Member
  • ***
  • Posts: 355
  • Windows 10
Re: WinFBE Suite 2.0.5 - ListView
« Reply #3 on: February 20, 2020, 02:33:05 PM »

Thanks, Paul. In the interim, I'll try that too.
Logged
Clive Richey
*“You Either Have To Be Part Of The Solution, Or You’re Going To Be Part The Problem.” Eldridge Cleaver.
#StaySafe, Always  Keep A Safe #SocialDistance, #WashYourHands Often and please, #StayHome!

Paul Squires

  • Administrator
  • Guru Member
  • *****
  • Posts: 9202
  • Windows 10
    • PlanetSquires Software
Re: WinFBE Suite 2.0.5 - ListView
« Reply #4 on: February 20, 2020, 02:35:53 PM »

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

Code: [Select]
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
Logged
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Paul Squires

  • Administrator
  • Guru Member
  • *****
  • Posts: 9202
  • Windows 10
    • PlanetSquires Software
Re: WinFBE Suite 2.0.5 - ListView
« Reply #5 on: February 20, 2020, 03:11:14 PM »

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.
Logged
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

SeaVipe

  • Senior Member
  • ***
  • Posts: 355
  • Windows 10
WinFBE Suite 2.0.6 - ListView - .Clear/WishList
« Reply #6 on: February 28, 2020, 03:33:35 PM »

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!
Logged
Clive Richey
*“You Either Have To Be Part Of The Solution, Or You’re Going To Be Part The Problem.” Eldridge Cleaver.
#StaySafe, Always  Keep A Safe #SocialDistance, #WashYourHands Often and please, #StayHome!

Paul Squires

  • Administrator
  • Guru Member
  • *****
  • Posts: 9202
  • Windows 10
    • PlanetSquires Software
Re: WinFBE Suite 2.0.5 - ListView
« Reply #7 on: February 28, 2020, 08:27:20 PM »

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.
Logged
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

SeaVipe

  • Senior Member
  • ***
  • Posts: 355
  • Windows 10
Re: WinFBE Suite 2.0.5 - ListView
« Reply #8 on: February 28, 2020, 09:55:58 PM »

Thanks, Paul.
OwnerDraw is not a simple solution...
« Last Edit: February 29, 2020, 01:04:00 PM by SeaVipe »
Logged
Clive Richey
*“You Either Have To Be Part Of The Solution, Or You’re Going To Be Part The Problem.” Eldridge Cleaver.
#StaySafe, Always  Keep A Safe #SocialDistance, #WashYourHands Often and please, #StayHome!