We help IT Professionals succeed at work.

Infragistics UltraGrid - how to display #1/1/1800# as blank ( as if null )

IvanGB
IvanGB asked
on
Hi all.

My UltraGrid 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.

Thanks in advance.
Comment
Watch Question

Kyle AbrahamsSenior .Net Developer

Commented:
Does the grid have a DataBinding Event?

if so you could say

if Date is nothing then
  MyTextBox.Text = ""
end if

(or label depending on what you're using)

Author

Commented:
Sorry Ged325, I probably wasn't very clear on my question. But thanks for the attention.
Kyle AbrahamsSenior .Net Developer

Commented:
so is this still an issue?
Commented:
Yep.
The thing is, the grid's date column is bound to a businessbiding source, which exposes the business object's properties to the grid. Our framework takes care of date controls to handle null date values. So, in my database, I won't allow null values for dates, and when the user blanks the date control, the StrataFrame framework automaticaly saves #1/1/1800# to the underlying table, and vice-versa, showing blank on the form when the date has #1/1/1800# on the table. All fine when the control is by itself dropped on a form.
Now I am dealing with this date column on an Infragistics UltraGrid and am not able to take advantadge of my StrataFrame control. The column is bound directly to the business object and I was trying to find a place to insert code doing the replacements.
Anyway, last night I ended up with a solution, creating an Unbound Column to the grid and dealing with its contents in the grid's InitializeRow and CellUpdated. So I manually set the date column to the values of this unbound column, and as I am in control of it, I can take care of null dates and the #1/1/1800# values on the table.
Thanks for your interest.
one simple solution is to take blank(null) from database by use case statement, as it is best practice to have business logic on database itself.

Author

Commented:
Thank you rajeshjamnadas, not an option at my scenario.
If you are binding to datatable, you can use for each dr as DataRow in dt.Select("Date='1/1/1800'")
dr("Date") = DBNull.Value.

or you can modify that property get part if value='1\1'1800' return nothing sort of.

If above two are not feasible than I think what you have done is more appropriate.

Author

Commented:
I am binding to a business binding source, and the business object property is set to not accept nulls, so I wouldn't be able to make the date property become null, at the same moment that I need to show it blank at the grid. And I also need to let the user blank it, which doesn't work as the property is set to not accept null. I know, it is just a matter of taking care of what is shown and what is entered, I just couldn't do it with the bound date column. The unbound gave me the freedom to deal with it and send whatever I want back to the table.