Solved

C# Listview formatting

Posted on 2011-09-16
9
347 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Log4Net custom Appender not being fired. 5 45
ConsoleSql 1 22
cs.Designer Issue(2) 2 23
Setting runtime form location 4 19
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
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.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

744 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

11 Experts available now in Live!

Get 1:1 Help Now