C# Listview formatting

Hello...
I have a listview in a C# project.
Here is my line of code that shows a current DateTime from an access Database

listView2.Items[x].SubItems.Add(ds.Tables["Notes"].Rows[x]["Tim"].ToString());"

It works fine... but instead of showing  "16-Sept-11 6:05:00 AM" I just want it to show the time... "6:05:00 AM"
Can someone show me what needs to be added to my line of code to change the formatting..
Please and thank you.



MrMayAsked:
Who is Participating?
 
wdosanjosConnect With a Mentor Commented:
OK. Please try the following:

listView2.Items[x].SubItems.Add(  ((DateTime)ds.Tables["Notes"].Rows[x]["Tim"]).ToString("t") );
0
 
Jacques Bourgeois (James Burger)PresidentCommented:
(datetime) (ds.Tables["Notes"].Rows[x]["Tim"]).ToShortTimeString();"
0
 
wdosanjosCommented:
Please try:

listView2.Items[x].SubItems.Add(ds.Tables["Notes"].Rows[x]["Tim"].ToString("t"));
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
MrMayAuthor Commented:
James Burger.. are you saying I should do this;  
listView2.Items[x].SubItems.Add(datetime)(ds.Tables["Notes"].Rows[x]["Tim"].ToShortTimeString());

if yes... the compiler does not like it... no such thing as ToshortTimeString();
0
 
MrMayAuthor Commented:
wdosanjos.... I tried that before... its no good... I get an error that reads   "No overload for method 'ToString" takes '1' arguments.
0
 
wdosanjosCommented:
Please let me know what is the value of ds.Tables["Notes"].Rows[x]["Tim"].GetType().Name.  It seems that it's not a DateTime.
0
 
MrMayAuthor Commented:
wdosanjos... I just ran that command... and it returns DateTime.
0
 
MrMayAuthor Commented:
wdosanjos... Yes... thank you that worked...

Thank you so much...   :)
0
 
MrMayAuthor Commented:
stuck with me... till we got a correct solution.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.