Solved

C# Listview formatting

Posted on 2011-09-16
9
348 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
  • 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
 

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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

930 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now