Click here to Skip to main content
15,899,632 members
Home / Discussions / C#
   

C#

 
Questionvariables changing back to null Pin
mh.3110782-May-09 6:16
mh.3110782-May-09 6:16 
AnswerRe: variables changing back to null Pin
Luc Pattyn2-May-09 6:26
sitebuilderLuc Pattyn2-May-09 6:26 
GeneralRe: variables changing back to null Pin
DaveyM692-May-09 6:38
professionalDaveyM692-May-09 6:38 
GeneralRe: variables changing back to null Pin
Pete O'Hanlon2-May-09 10:36
mvePete O'Hanlon2-May-09 10:36 
AnswerRe: variables changing back to null Pin
DaveyM692-May-09 6:39
professionalDaveyM692-May-09 6:39 
QuestionSend RTF instead of HTML in outlook Pin
lastpunisher2-May-09 3:47
lastpunisher2-May-09 3:47 
QuestionHow to retrieve full path of file or image from imagelist Pin
Aljaz1112-May-09 3:09
Aljaz1112-May-09 3:09 
QuestionListView Binding - ObservableCollection [modified] Pin
b4ip2-May-09 3:04
b4ip2-May-09 3:04 
Overview
WPF Project (Visual Studio 2008)
I am using a ListView (with GridView) bound to an ObservableCollection, which includes a DateTime field.

<br />
        public class RecordData<br />
        {<br />
            public int ID { get; set; }<br />
            public DateTime DateNR { get; set; }<br />
        }<br />


The GridView column for 'DateNR' is specified as follows:
<br />
        GridViewColumnHeader gvch = new GridViewColumnHeader();<br />
        GridViewColumn gvc = new GridViewColumn();<br />
        Binding bind = new Binding("DateNR");<br />
        bind.Converter = new FormattingConverter();<br />
        bind.ConverterParameter = @"{0:dd-MMM-yy}";<br />
        gvc.Width = 80;<br />
        gvc.DisplayMemberBinding = bind;<br />
        gvch.Content = "NR Date";<br />
        gvc.Header = gvch;<br />
        myGridView.Columns.Add(gvc);<br />


When I populate the collection from the database, DateNR can be null and is therefore only assigned to the collection property if it is NOT null.
<br />
        SqlConnection sqlConn = new SqlConnection(myConnectionString);<br />
        SqlCommand sqlComm = new SqlCommand("...", sqlConn);<br />
        SqlDataReader sqlDR = sqlComm.ExecuteReader();<br />
        // ...<br />
        RecordData rd = new RecordData();<br />
        rd.ID = sqlDR.GetInt32(0);<br />
        if (sqlDR.IsDBNull(1) == false)<br />
            rd.DateNR = sqlDR.GetDateTime(1);<br />
        // ...<br />
       _MyCollection.Add(rd);<br />


Problem
The problem is that the ListView is displaying a date of "01-Jan-01" in the 'DateNR' column for all items that were not assigned a date. How do I stop this as I don't want the user to see a date when there shouldn't be one.

I need the 'DateNR' property in the collection to be a DateTime value and not a string value because this column is used for sorting.

Any ideas would be welcome. thanks

modified on Sunday, May 3, 2009 1:50 AM

AnswerRe: ListView Binding - ObservableCollection Pin
Henry Minute2-May-09 5:01
Henry Minute2-May-09 5:01 
QuestionBindingNavigator save button does not save info to table Pin
Vloops2-May-09 2:44
Vloops2-May-09 2:44 
AnswerRe: BindingNavigator save button does not save info to table Pin
Mycroft Holmes2-May-09 3:11
professionalMycroft Holmes2-May-09 3:11 
GeneralRe: BindingNavigator save button does not save info to table Pin
Vloops2-May-09 4:11
Vloops2-May-09 4:11 
GeneralRe: BindingNavigator save button does not save info to table Pin
DaveyM692-May-09 6:43
professionalDaveyM692-May-09 6:43 
GeneralRe: BindingNavigator save button does not save info to table Pin
Vloops2-May-09 6:46
Vloops2-May-09 6:46 
GeneralRe: BindingNavigator save button does not save info to table Pin
DaveyM692-May-09 6:50
professionalDaveyM692-May-09 6:50 
GeneralRe: BindingNavigator save button does not save info to table Pin
Vloops2-May-09 6:55
Vloops2-May-09 6:55 
GeneralRe: BindingNavigator save button does not save info to table Pin
Mycroft Holmes2-May-09 14:30
professionalMycroft Holmes2-May-09 14:30 
QuestionTemplate Engine for C# website? Pin
Member 3653372-May-09 2:41
Member 3653372-May-09 2:41 
AnswerRe: Template Engine for C# website? Pin
Mycroft Holmes2-May-09 3:07
professionalMycroft Holmes2-May-09 3:07 
GeneralRe: Template Engine for C# website? Pin
Member 3653372-May-09 3:34
Member 3653372-May-09 3:34 
GeneralRe: Template Engine for C# website? Pin
Pete O'Hanlon2-May-09 10:37
mvePete O'Hanlon2-May-09 10:37 
GeneralRe: Template Engine for C# website? Pin
Mycroft Holmes2-May-09 14:32
professionalMycroft Holmes2-May-09 14:32 
Questiontextbox Pin
sasan562-May-09 2:28
sasan562-May-09 2:28 
AnswerRe: textbox Pin
Luc Pattyn2-May-09 3:55
sitebuilderLuc Pattyn2-May-09 3:55 
QuestionMouse Events in windows application C# [modified] Pin
Mads1151-May-09 21:54
Mads1151-May-09 21:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.