我用CSV文件保存了数据,每组数据都包涵三个string型的数据,分别为序号,时间和内容,之间用分号隔开:
00;2013-08-01 08:08:10;你好你好你好
06;2013-08-01 08:08:10;你好你好你好
32;2013-08-01 08:08:10;你好你好你好
00;2013-08-01 08:08:35;你好你好你好
32;2013-08-01 08:08:36;你好你好你好
06;2013-08-01 08:08:36;你好你好你好
00;2013-08-01 08:12:49;你好你好你好我想用listbox显示内容是按时间的"倒序"来排列,或者按序号来排列
如何解决??
下面的代码是我用来直接显示csv文件,没排序处理的 try
{
string path = Application.StartupPath + "\\AlarmMessage"; DirectoryInfo TheFolder = new DirectoryInfo(path);
foreach (FileInfo NextFile in TheFolder.GetFiles())
{
ArrayList arr = AdsBaseClass.LoadAlarmMsg(NextFile.FullName);
for (int i = 0; i < arr.Count; i++)
{
string[] temp = arr[i].ToString().Split(';');
alarmList.Items.Add(string.Format("{0}.{1}", temp[0], temp[2]));//temp[0]序号 temp[1]时间 temp[2]内容
alarmList.OtherItems.Add(temp[1]);
}
}
}
catch (System.Exception ex)
{ }
00;2013-08-01 08:08:10;你好你好你好
06;2013-08-01 08:08:10;你好你好你好
32;2013-08-01 08:08:10;你好你好你好
00;2013-08-01 08:08:35;你好你好你好
32;2013-08-01 08:08:36;你好你好你好
06;2013-08-01 08:08:36;你好你好你好
00;2013-08-01 08:12:49;你好你好你好我想用listbox显示内容是按时间的"倒序"来排列,或者按序号来排列
如何解决??
下面的代码是我用来直接显示csv文件,没排序处理的 try
{
string path = Application.StartupPath + "\\AlarmMessage"; DirectoryInfo TheFolder = new DirectoryInfo(path);
foreach (FileInfo NextFile in TheFolder.GetFiles())
{
ArrayList arr = AdsBaseClass.LoadAlarmMsg(NextFile.FullName);
for (int i = 0; i < arr.Count; i++)
{
string[] temp = arr[i].ToString().Split(';');
alarmList.Items.Add(string.Format("{0}.{1}", temp[0], temp[2]));//temp[0]序号 temp[1]时间 temp[2]内容
alarmList.OtherItems.Add(temp[1]);
}
}
}
catch (System.Exception ex)
{ }
解决方案 »
- 简单的调色板问题
- web 实现 导出word
- 。NET应用程序如何做成一个插件
- 请问一个能弹出提示的问题!
- c#程序员交流的天堂QQ:群14354766
- 如何取得当前程序的版本等信息?
- 怎么不使用SQL Server分布式管理对象,枚举出服务器上的数据库已经数据库中的表?
- 请教各位大哥。。。多谢!!
- ListView怎样实现刷新啊!!!!
- 我有一个链表,怎么在链表当中插入一个节点,还有删除任意位置的节点
- VS2010使用clickonce进行发布,如何获取发布的版本信息??
- System.Runtime.InteropServices.COMException (0x80004005): 对 COM 组件的调用返回了错误 HRESU
new Info("00",DateTime.Parse("2013-08-01 08:08:10"),"你好你好你好"),
new Info("06",DateTime.Parse("2013-08-01 08:08:10"),"你好你好你好"),
new Info("32",DateTime.Parse("2013-08-01 08:08:10"),"你好你好你好"),
new Info("00",DateTime.Parse("2013-08-01 08:08:35"),"你好你好你好"),
new Info("32",DateTime.Parse("2013-08-01 08:08:36"),"你好你好你好"),
new Info("06",DateTime.Parse("2013-08-01 08:08:36"),"你好你好你好"),
new Info("00",DateTime.Parse("2013-08-01 08:12:49"),"你好你好你好"),
}; var result = from p in list orderby p.CurrentTime descending select p; IList<Info> newList = result.ToList<Info>();
foreach (Info item in newList)
{
Console.WriteLine(item.CurrentTime.ToString("yyyy-MM-dd HH:mm:ss"));
}public class Info
{
public Info()
{ } public Info(string id, DateTime currentTime, string information)
{
this.ID = id;
this.CurrentTime = currentTime;
this.Information = information;
} public string ID { get; set; }
public DateTime CurrentTime { get; set; }
public string Information { get; set; }
}
class Program
{
static void Main(string[] args)
{
CSVFile file = new CSVFile(); file.Sort(CSVItem.SortNo);
file.Show(); file.Sort(CSVItem.SortDateTime);
file.Show(); Console.ReadLine();
} public class CSVItem
{
public int No { get; set; }
public DateTime DateTime { get; set; }
public string Msg { get; set; } public CSVItem() { } public static int SortNo(CSVItem item1, CSVItem item2)
{
int result = -1;
if (item1.No > item2.No)
result = 1;
else if (item1.No < item2.No)
result = -1;
else
result = 0;
return result;
} public static int SortDateTime(CSVItem item1, CSVItem item2)
{
int result = -1;
if (item1.DateTime > item2.DateTime)
result = 1;
else if (item1.DateTime < item2.DateTime)
result = -1;
else
result = 0;
return result;
} public override string ToString()
{
return string.Format("No:{0}-Time:{1}-Msg:{2}", No, DateTime, Msg);
}
} public class CSVFile
{
private List<CSVItem> items; public CSVFile()
{
//测试
items = new List<CSVItem>();
items.Add(new CSVItem() { No = 4, DateTime = DateTime.Now.AddDays(2), Msg = "111" });
items.Add(new CSVItem() { No = 1, DateTime = DateTime.Now, Msg = "333" });
items.Add(new CSVItem() { No = 3, DateTime = DateTime.Now.AddDays(4), Msg = "444" });
items.Add(new CSVItem() { No = 2, DateTime = DateTime.Now.AddDays(6), Msg = "155511" });
} public CSVFile(string fileName)
{
//从文件读,填充到items
} public void Sort(Comparison<CSVItem> type)
{
items.Sort(type);
} public void Show()
{
for (int i = 0; i < items.Count; i++)
{
Console.WriteLine(items[i]);
}
}
}
}