views:

164

answers:

2

Ultrawingrid 9.2 VS2008 .net 3.5

My wingrid uses a bindingsource. All datetimes which are null in SQL Server are delivered to the bindingsource as #1/1/1800#

I would like Ultrawingrid to display this date as blank as it would a null from source.

Also, if the date is null in the grid ( i.e. blanked out ) I would like to update the data source to the date #1/1/1800# ( the framework takes care of getting that date back into the backend as a null )

This seems like it should be a trivial matter but I can find no documentation on just where to intervene so the grid will see a particular date as a null and save a null as a particular date.

This is the direction I've been headed but I don't think either is the right place and I can't even get the syntax to work in the BeforeRowUpdate as I cannot see how to set a value that is passed to the data binding without setting the value of control itself, which I think has to remain null in order to display as blank

Private Sub ugPropMaster_BeforeRowUpdate(ByVal sender As Object, ByVal e As _
   Infragistics.Win.UltraWinGrid.CancelableRowEventArgs) Handles _
   ugPropMaster.BeforeRowUpdate

    If e.Row.Cells.Item("Exdate").Value Is Nothing Then

        e.Row.Cells("Exdate").Value = CDate(#1/1/1800#)

    End If

 End Sub



  Private Sub ugPropMaster_InitializeRow(ByVal sender As Object, ByVal e As _
    Infragistics.Win.UltraWinGrid.InitializeRowEventArgs) Handles _
    ugPropMaster.InitializeRow

    If CDate(e.Row.Cells.Item("Exdate").Value) = CDate(#1/1/1800#) Then
        e.Row.Cells.Item("Exdate").Value = Nothing
    End If

End Sub

Guidance much appreciated

A: 

Do you have an UltraDataSource backing your grid? If so, then e.Row.ListObject should be the UltraDataRow corresponding to the grid's row.

I often keep a reference to a business object in the UltraDataRow's Tag property, and I end up with InitializeRow methods that look like this (apologies for C# instead of VB.net):

    private void mygrid_InitializeRow(object sender, InitializeRowEventArgs e)
    {
        try
        {
            UltraDataRow udr = e.Row.ListObject as UltraDataRow;
            if (udr == null)
            {
                return;
            }

            MyRecord rec = udr.Tag as MyRecord;
            if (rec == null)
            {
                return;
            }

            ...

You can also access the underlying datasource values from udr.Band.Cells.

Hope this helps!

PaulF
Thank you, Paul. No, I don't have a UDS under the grid - I am using our framework's businessbindingsource which extends bindingsource. But I think this may be a direction to explore - perhaps using our BBS as the source for the UDR ... It may give me the layer of abstraction I need. I have something working using an unbound column and handlers for InitializeRow and AfterCellUpdate. It isn't pretty, but it works.I will look into UltraDataSource and see if I can come up with something there. Thanks again.Charles
Charles Hankey
A: 

Can you make the property on the binding source a nullable DateTime? ?

skimania