Solved

C# Listview formatting

Posted on 2011-09-16
9
351 Views
Last Modified: 2013-12-17
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.



0
Comment
Question by:MrMay
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
9 Comments
 
LVL 40
ID: 36551440
(datetime) (ds.Tables["Notes"].Rows[x]["Tim"]).ToShortTimeString();"
0
 
LVL 23

Expert Comment

by:wdosanjos
ID: 36551441
Please try:

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

Author Comment

by:MrMay
ID: 36551551
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
Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

 

Author Comment

by:MrMay
ID: 36551558
wdosanjos.... I tried that before... its no good... I get an error that reads   "No overload for method 'ToString" takes '1' arguments.
0
 
LVL 23

Expert Comment

by:wdosanjos
ID: 36551587
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
 

Author Comment

by:MrMay
ID: 36551606
wdosanjos... I just ran that command... and it returns DateTime.
0
 
LVL 23

Accepted Solution

by:
wdosanjos earned 500 total points
ID: 36551618
OK. Please try the following:

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

Author Comment

by:MrMay
ID: 36551640
wdosanjos... Yes... thank you that worked...

Thank you so much...   :)
0
 

Author Closing Comment

by:MrMay
ID: 36551652
stuck with me... till we got a correct solution.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question