• Welcome to PlanetSquires Forums.
 

ListView Control

Started by SeaVipe, August 16, 2022, 09:10:21 PM

Previous topic - Next topic

SeaVipe

Hi Paul,
I have a form (frmRecurringPayments) with a ListView control. The first time the form is shown the listview displays correctly, Close the form. Subsequent frmRecurringPayments.Show calls has the columns still set from the original .Show plus an additional set of columns (repeat, repeat):

' From  frmRecurringPayments_Load Event
With frmRecurringPayments.lvRecurPays
   
' This line added to solve issue with multiple Columns        
.Columns.Clear

    .Columns.Add("ID",          65, TextAlignment.Center)
    .Columns.Add(" Payee",    200, TextAlignment.Left)
    .Columns.Add(" Desc",      268, TextAlignment.Left)
    .Columns.Add("DueDate",    65, TextAlignment.Center)
    .Columns.Add("YearValid",  65, TextAlignment.Center)
    .Columns.Add("Amount ",    65, TextAlignment.Right)
   
End With

I added the line as seen in the above code and it works just fine.

My question is, do the controls on a form not get destroyed when the form closes?
Clive Richey

Paul Squires

Hi Clive, I will test tomorrow to try to duplicate what you are seeing. You are using the .Show method to display the form. This shows the form as modeless. Is that your intention or are you wanting to display it as a modal form that takes control of input until it is closed? How are you initiating the display of this form (are you pressing a button or selecting top menu item that then displays the form)?

How are you closing the Form? Pressing the "X" on the form or using code to close it? The form's .Close method should call the methods FormClosing and FormClosed. Are you doing anything in those methods? If not, then the code should then call the winapi DestroyWindow that triggers WM_DESTROY and then finally WM_NCDESTROY where the control data is removed from WinFormsX internal data structures.

The fact that in your case the columns seem to exist between incarnations of the form being shown would indicate to me that the internal WinForm's data structures are not being cleared.

I am typing all of this based on my memory so tomorrow I will create a test example to try to duplicate what you are seeing.

 
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Paul Squires

Hi Clive,

Yes, I confirm that there is a problem as you have described. I have added it to my bug/todo tracker and will fix the framework.

In the meantime, you should continue to add these lines to your Load method if you are reusing the form/listview multiple times.

   ' This line added to solve issue with multiple Columns       
   .Columns.Clear
   .Items.Clear

You most like likely need to clear both the Columns *and* the rows.

Thanks,
Paul
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

SeaVipe

Thanks, Paul,
I do have .Items.Clear also but failed to mention it as I was more interested in pointing out that .Columns.Clear did the trick.

Also I call the form thusly: frmRecurringPayments.ShowDialog(frmMain.hWindow) from a top menu item and close with
frmRecurringPayments_btnClose_Click: frmRecurringPayments.Close
This is a very simple form with just a listview, 1 Frame, 6 text boxes and 4 buttons. There are no Closed or Closing events selected.
Clive Richey