469,953 Members | 2,271 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,953 developers. It's quick & easy.

How to Set Empty String in "System.DateTime?" The nullable DateTimeType.

Hi,

I am using property like this..
private DateTime? _propName;

public DateTime? PropName

{

get { return _propName; }

set { _propName = value; }

}

Now, the objects of this properties parent Type are shown in a grid in our
application.

This date is populated when user does some action. When no action has been
taken, it is fetched as null for the database.

Now, In the grid I want to show it as empty string, but right now, it shows
it as 0.

How do I get this nullable reference type to represent an empty string?/

Regards,

Sugandh


Mar 29 '07 #1
3 11764
Just to add... I am using .net 2.0, visual studio .net 2005.

"Sugandh Jain" <su**********@nirvana-sol.comwrote in message
news:uo**************@TK2MSFTNGP02.phx.gbl...
Hi,

I am using property like this..
private DateTime? _propName;

public DateTime? PropName

{

get { return _propName; }

set { _propName = value; }

}

Now, the objects of this properties parent Type are shown in a grid in our
application.

This date is populated when user does some action. When no action has been
taken, it is fetched as null for the database.

Now, In the grid I want to show it as empty string, but right now, it
shows it as 0.

How do I get this nullable reference type to represent an empty string?/

Regards,

Sugandh


Mar 29 '07 #2
How do I get this nullable reference type to represent an empty
string?/
Actually, that's a nullable value type, which is itself a value type.
However, it all looks fine for me (see below) - but I guess it comes
down to the format options on the columns, assuming that you are using
proper TypeConverter usage and not just calling .ToString() yourself:

using System;
using System.Windows.Forms;
using System.ComponentModel;
using System.Diagnostics;

class MyData {
private DateTime? a, b, c;
public DateTime? A { get { return a; } set { a = value; } }
public DateTime? B { get { return b; } set { b = value; } }
public DateTime? C { get { return c; } set { c = value; } }

public MyData() {
A = null; // null
B = new DateTime(); // non-null zero
C = DateTime.Now; // non-zero
}
}

class MyProgram {

static void Main() {
BindingList<MyDatalist = new BindingList<MyData>();
list.Add(new MyData());
using (Form f = new Form())
using (DataGridView dgv = new DataGridView()) {
dgv.AutoGenerateColumns = true;
dgv.Dock = DockStyle.Fill;
dgv.DataSource = list;
f.Controls.Add(dgv);
Application.Run(f);
}
}
}
Mar 29 '07 #3
Thanks I got it. Set the Null Text for the column in the grid to empty
string. and left the value of the volumn to be null.
So, it does not show a default date, but the empty string..

Thanks,
Sugandh

"Sugandh Jain" <su**********@nirvana-sol.comwrote in message
news:uo**************@TK2MSFTNGP02.phx.gbl...
Hi,

I am using property like this..
private DateTime? _propName;

public DateTime? PropName

{

get { return _propName; }

set { _propName = value; }

}

Now, the objects of this properties parent Type are shown in a grid in our
application.

This date is populated when user does some action. When no action has been
taken, it is fetched as null for the database.

Now, In the grid I want to show it as empty string, but right now, it
shows it as 0.

How do I get this nullable reference type to represent an empty string?/

Regards,

Sugandh


Mar 29 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Picho | last post: by
8 posts views Thread by craigkenisston | last post: by
2 posts views Thread by GossTremontTech | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.