How can I add a DateTime value along with 2 string values into a ListView? I've tried...
String[] row = { Time.Value.ToString(), "Example Text", "Example Text"};
listView1.Items.AddRange(row);
but I get conversion errors.
How can I add a DateTime value along with 2 string values into a ListView? I've tried...
String[] row = { Time.Value.ToString(), "Example Text", "Example Text"};
listView1.Items.AddRange(row);
but I get conversion errors.
Is this a Windows Forms ListView? If so, you want to add ListViewItem's to it. ListViewItem can take an array of strings to represent its columns.
I don't think you're question has anything specifically to do with a ListView. It sounds like you just need to know how to extract the time from a DateTime value into a string.
Use the DateTime.ToString(String) method with the "T" standard format (MSDN standard DateTime formats):
Time.Value.ToString("T")
That would return the following for en-us:
3:51:24 PM
If you are just getting started with a ListView, you can save yourself a lot of pain and trouble by using ObjectListView -- an open source wrapper around .NET WinForms ListView. It makes working with a ListView much easier as well as solving some very annoying problems that you will otherwise encounter.
For example, it knows how to handle dates, including sorting, grouping and editing.
In another question, you asked about saving and restoring the state of the ListView. ObjectListView has methods to do those tasks as well.
Save yourself pain now -- use ObjectListView :)