【发布时间】:2013-12-08 01:38:34
【问题描述】:
我正在使用 vs 2013 在 winforms c# 中创建一个应用程序。
在应用程序中,我有一个文本文件,我使用时间选择下拉列表中的自定义格式以 int 格式表示时间。
然后我想在一个可选择的列表视图中显示该文本文件中的内容,我可以从中将其从文本文件等中删除。我几乎就在那里,但是当我尝试将项目添加到他们所做的列表框中时似乎添加了但是它们不能正确显示。
例如说在我的文本文件中有
22102210
19101610
17182218
10272227
这就是它应该如何在列表视图中显示为可供删除的可选选项。
目前显示不正确,显示为 1.. 2.. 1..
有人可以帮我指出正确的方向吗?为什么会发生这种情况?非常感谢任何帮助。这是我的课。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Chronos
{
public partial class Interface : Form
{
private string[] getTimes = System.IO.File.ReadAllLines(@"G:\Dropbox\University\Chronos\Application\Chronos\Chronos\AdminAccount\Times.txt");
public Interface()
{
InitializeComponent();
}
private void Interface_Load(object sender, EventArgs e)
{
PopulateList();
}
private void PopulateList()
{
int size = getTimes.Length;
lstTime.Items.Clear();
GetTimes();
for (int i = 0; i < size; i++)
{
lstTime.Items.Add(getTimes[i]);
}
}
private void GetTimes()
{
string[] getTimes = System.IO.File.ReadAllLines(@"G:\Dropbox\University\Chronos\Application\Chronos\Chronos\AdminAccount\Times.txt");
}
private void btnAdd_Click(object sender, EventArgs e)
{
string time = pickerTimeStart.Value.Hour.ToString() + pickerTimeStart.Value.Minute.ToString() + pickerTimeEnd.Value.Hour.ToString() + pickerTimeEnd.Value.Minute.ToString();
System.IO.File.AppendAllText(@"G:\Dropbox\University\Chronos\Application\Chronos\Chronos\AdminAccount\Times.txt", time + Environment.NewLine);
PopulateList();
MessageBox.Show("Time added", "Ok");
//PopulateList();
}
}
}
【问题讨论】: