StrataFrame Forum

How to display empty dates in ListView?

http://forum.strataframe.net/Topic30997.aspx

By Larry Tucker - 3/2/2012

Well, I'm back to SF after a few years and some other adventures (an Ironspeed web app, some data mining experience...) and am converting a VFP (VPME) application.  (Hello to some old VPME'ers out there like Edhy).  I'm really liking the core SF functionality but have some questions around the fringes.

So my first question concerns displaying empty dates.  I see that the DateBox is now the preferred way of editing dates and it has an EmptyValue property for trapping a place holder value (like '1/1/1800') and displaying it as blank. 

What is the best way to trap and hide these place holder dates in other places, such as in ListView columns?  I see I have two options to format a column:  Format String and PopulatedThroughEvent.  I suspect the preferred way is to use PopulatedThroughEvent to trap the place holder date value and return a "" string.  Is that about right?  Any examples?

Thanks in advance,

Larry
By Edhy Rijo - 3/2/2012

Hi Larry,
Welcome back!!!

Well, StrataFrame handle this situation very easy via the "NULL Value Option" in the "Custom Field Properties" in the Business Object Mapper.  Just select a null option like "Return Altername on Null" and set it to the empty date value like this: New Date(1800,1,1) so when you get a Null date from SQL Server, you are actually getting 1/1/1800 and SF will translate that for you in every SF control including the ListView, so you don't have to anything else.
http://forum.strataframe.net/Uploads/Images/3d9951a5-1f50-43bb-a24d-ceca.png
By Larry Tucker - 3/2/2012

Hi Edhy,

It is good to be back.  And I see you've really mastered SF... and are continuing to help a lot in the forum.

This is just what I needed.  Excellent.  Thanks.

Larry
By Edhy Rijo - 3/2/2012

Hi Larry,
Larry Tucker (3/2/2012)
... I see you've really mastered SF... and are continuing to help a lot in the forum.


Mastered SF, No really, still have a lot to learn.  Just that by using it almost every day you get more familiar with the tools Smile

I noticed you mentioned IronSpeed, if you don't mind, I would like to know about your experience with it, I will send you a private message with my phone.
By Larry Tucker - 3/2/2012

Edhy,

Was nice chatting just now. 

As for the display issue, I think I've got the BO translation working but it still shows in the ListView as 1/1/1800.

(Am trying to upload a screen shot here).

Will keep poking around at the problem...

Larry
By Edhy Rijo - 3/4/2012

Hi Larry,
Here is what you need to do to get your empty dates to be shown as blank in the listview:
  • In the ListView Population Setting, set the "Population Type" of the date column to be "PopulatedThroughEvent
http://forum.strataframe.net/Uploads/Images/a10854a9-10cf-487f-bc58-8067.png
  • Create a handle for the Listview.RowPopulating and enter code like this:

    Private Sub ListView1_RowPopulating(e As MicroFour.StrataFrame.UI.Windows.Forms.RowPopulatingEventArgsHandles ListView1.RowPopulating
         Using bo As bizCustomers = CType(e.BusinessObject, bizCustomers)
             If bo.cust_Created = #1/1/1800# Then
                 e.Values(2).DisplayValue = String.Empty
             End If
         End Using
     End Sub

That should take care of this issue. Also, if you will be manipulating the data in the listview, I prefer to add an instance of the BO, fill the data of the BO, then requery the ListView using the
BusinessCloneDataType.ClearAndFillFromDefaultView as below and set the ListView.AutoNavigateToSelectedRecord = True

    Private Sub ListView1_ListPopulating(e As MicroFour.StrataFrame.UI.ListPopulatingEventArgsHandles ListView1.ListPopulating
         e.Parameters(0).Value = Me.BizCustomers1
         e.Parameters(1).Value = MicroFour.StrataFrame.Business.BusinessCloneDataType.ClearAndFillFromDefaultView
     End Sub

By Larry Tucker - 3/6/2012

Hi Edhy,

Thank you for following up about the display issue.  That solved it.

BTW, how are you formatting the code and uploading the screen shots in your replies?  They are very clear. Is there a Forum guide somewhere that explains this?

Larry
By Edhy Rijo - 3/6/2012

Hi Larry,

Glad it is working for you now.

Larry Tucker (3/6/2012)
BTW, how are you formatting the code and uploading the screen shots in your replies?  They are very clear. Is there a Forum guide somewhere that explains this?

I use Firefox browser and when replying simply click the "IF Code" and select "Code Snipped", then I copy and paste my code between the codesnippet tags and to keep it formatted properly, I have to add a carrier return at the end of each copied line, otherwise it would be pasted as a one line only.

See Sample Image:


         '-- Bypass this method when the form is being loaded.
         If Me.FormIsLoading Then
             '-- Clear the BO so no previous record are re-used
             '   This line is causing a problem with previously modified records.
             '   for now do not clear the BO.  8/12/2009
             Me.BizTransactionItemsStock1.Clear()

             ' ER 10/27/2010: Added the Requery to force the Edit Button cmdChangeActiveQtyAndStartValues
             ' to be enabled/disable properly.
             Me.lstItemsStock.Requery()
             Exit Sub
         End If


http://forum.strataframe.net/Uploads/Images/9e82e30b-8333-4c6b-b54c-5fe0.png
By Larry Tucker - 3/8/2012

Thanks Edhy,

Using Firefox helped me see the formatting codes in the text editor.  They were hidden in IE...

So here is my code (for various reasons I'm using 1/1/2200 to indicate an "open" ending date)...


Private Sub CoverageListView_RowPopulating(e As MicroFour.StrataFrame.UI.Windows.Forms.RowPopulatingEventArgs)
 Handles CoverageListView.RowPopulating
        Dim bo As CoverageBO
        bo = e.BusinessObject
        If bo.COV_END = #1/1/2200# Then
            e.Values(6).DisplayValue = String.Empty
        Else
            e.Values(6).DisplayValue = bo.COV_END.ToShortDateString
        End If
    End Sub


And here is the result showing blank "End Pop" column in the listview on a test screen...

http://forum.strataframe.net/Uploads/Images/e960cf1c-ff7a-4efe-9361-e8ac.jpg


Larry
By Edhy Rijo - 3/8/2012

Hi Larry,

I am glad you figured out, it looks good.  One thing I would change in your code is instead of using Dim bo As CoverageBO I would use the "Using...End Using" as posted in one of my sample code in previous posting in this thread just to avoid any possible memory leak by no disposing the bo object and keep in mind that this code will run for each created row in the listview, so with many records loaded, it could just bloat up at any point.
By Larry Tucker - 3/9/2012

Edhy,

Interesting.  I noticed your "Using..." approach and did not realize there was any difference in terms of memory.  I'm trying to get the hang of VB object instantiation and syntax (as opposed to VFP) and my approach looked clearer to me.  Thanks for the suggestion. 

Just to better understand.  Would adding bo.dispose() at the end of the subroutine address the potential memory bloat / leak? 

Would the "Using..." still be faster than "Dim bo as..." because it requires less initial construction / memory allocation?

Finally, I'm curious about the CTYPE() conversion you used.  It looks like the code will work without it (below).  Is there a benefit to adding it that I am not seeing?

Again,  I appreciate the discussion and extension beyond the original question.  Hopefully others find it useful too.

Larry


    Private Sub CoverageListView_RowPopulating(e As MicroFour.StrataFrame.UI.Windows.Forms.RowPopulatingEventArgs)
Handles CoverageListView.RowPopulating
        'Dim bo As CoverageBO
        'bo = e.BusinessObject
        Using bo As CoverageBO = e.BusinessObject
            If bo.COV_END = #1/1/2200# Then
                e.Values(6).DisplayValue = String.Empty
            Else
                e.Values(6).DisplayValue = bo.COV_END.ToShortDateString
            End If
        End Using
    End Sub
By Edhy Rijo - 3/9/2012

Hi Larry,
Again,  I appreciate the discussion and extension beyond the original question.  Hopefully others find it useful too.

Me too Smile

Just to better understand.  Would adding bo.dispose() at the end of the subroutine address the potential memory bloat / leak? 

Yes, but as per MS documentation, the Using...End Using does a better job and it is recommended unless it is not supported by the object to be instantiated.  Check the MS documentation for better reference.

Finally, I'm curious about the CTYPE() conversion you used.  It looks like the code will work without it (below).  Is there a benefit to adding it that I am not seeing?

In most cases, you know what the object's type is, and it may work just fine without the CTYPE(), but keep in mind that in this particular case, all SF BO are inherited form the MicroFour.StrataFrame.Business.BusinessLayer which has all sort of common properties and methods to the BO, if you have your own Base BO class where you inherit your BO from, then custom methods or property will not show up in the e.BusinessObject argument, because the e.BusinessObject is of type BusinessLayer and do not have your custom methods or properties.  So Casting to the correct expected object is a good practice, not common to us coming from a VFP environment when object types are not enforced, but very important in .Net environment.
By Larry Tucker - 3/9/2012

Edhy,

Thanks again for the elaboration.


if you have your own Base BO class where you inherit your BO from,


I certainly did this in VPME... we all probably did because the framework encouraged it (having an intermediate "base" class between that of the framework and the actual classes in a specific app:  vpm... dev... and pro... classes).  Haven't thought about it yet in SF.  How much do you have the SF classes subclassed?

Larry
By Terry Bottorff - 3/9/2012

This has been a great discussion. I am fighting with the ctype command also and this just helped me understand a bit more.

I want to also look into the Using.... issue which I know I have not utilized but can start now.

Thank both of you for the dialog.
By Edhy Rijo - 3/9/2012

Larry Tucker (3/9/2012)
...How much do you have the SF classes subclassed?

Not much, just a Base class for the BO which is highly recommended since I have created generic methods that are used by all BOs in this class.  Also since I started using DevExpress a year ago I use the "MicroFour StrataFrame Inherited UI" assembly to be able to use ready made SF controls which inherit from my DevExpress classes and make it easier to use DevExpress controls.  Also I have created my own DevExpress Grid class and some report controls.

Inheritance is a very power concept as in VFP, but it is done different than VFP.  At some point the right way to do this would be to create my own assembly that inherited from SF and then use those to create my applications, but so far I have not had the need to do all that like we did in VFP/VPM.
By Larry Tucker - 3/11/2012

Edhy,

Yea, I guess I start thinking about subclasses when I realize I have written the same thing 4 or 5 times... (or is it 14 or 15?Whistling).  It's amazing how much laziness can appeal:  I'll just copy this code one more time and next time I'll subclass the whole thing.

So I assume I'll start repeating myself in all my BOs and finally say, "Duh"... put this in my own base class.  Might be good to create my own BO base class before I realize I need it.  Doesn't hurt to leave it blank until then.

Larry
By Edhy Rijo - 3/12/2012

Hi Larry,

Larry Tucker (3/11/2012)
So I assume I'll start repeating myself in all my BOs and finally say, "Duh"... put this in my own base class.


That is exactly what happened to me.  I was kind of intimidated to create my own BO base class, until the guys here in the forum, Trent, Ivan, Greg, showed me how easy it was to do that, much easier than in VFP and vey stable.

Larry Tucker (3/11/2012)
Might be good to create my own BO base class before I realize I need it. Doesn't hurt to leave it blank until then.


Yeap, go for it and can assure you once you get the confidence you would start adding more and more functionality.