Solved

C# Listview formatting

Posted on 2011-09-16
9
349 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How can i use linq for parsing string datetime to real datetime? 16 44
Cant save 3D 4 19
Send SMS from VB via Sierra Wireless Modem 2 21
Powershell File Sort 8 23
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

815 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