0
因此,我的组合框中的列表来自文本文件。该程序允许用户从组合框中选择一个项目。选定的项目应该从组合框和文本文件中删除,也可以通过点击按钮。如何从文本文件中的组合框中删除选定的项目
该代码允许程序来从文本文件中的项目,我的组合框:
string location = @"C:\\Users\\LMCPENA98\\Desktop\\COE114LPROJECT_MILLENNIUM_PAWS\\MillenniumPaws\\MillenniumPaws\\bin\\Debug\\Files.txt";
string[] temp = File.ReadAllLines(location);
int[] TagNumber = new int[temp.Length];
string[] Breed = new string[temp.Length];
string[] Name = new string[temp.Length];
decimal[] Price = new decimal[temp.Length];
//Getting all the values i the text file
for (int i = 0; i < TagNumber.Length; i++)
{
TagNumber[i] = int.Parse(temp[i].Substring(0, temp[i].IndexOf("-")));
Breed[i] = temp[i].Substring(0, temp[i].IndexOf("+"));
Breed[i] = Breed[i].Substring(Breed[i].LastIndexOf("-") + 1);
Name[i] = temp[i].Substring(0, temp[i].IndexOf("="));
Name[i] = Name[i].Substring(Name[i].LastIndexOf("+") + 1);
Price[i] = decimal.Parse(temp[i].Substring(temp[i].LastIndexOf("=") + 1));
}
Pound p;
for (int i = 0; i < Breed.Length; i++)
{
if (Breed[i] == cmbBx_breed.Text)
{
p = new Pound(TagNumber[i], Name[i], Price[i]);
cmbBx_opts.Items.Add(p.GetEntry());
}
}
}
else
{
cmbBx_breed.Text = null;
}
这是我如何让知道我在做选择的项目的程序:
private void btn_buy_Click(object sender, EventArgs e)
{
new MessageBox_TYBuying().Show();
cmbBx_opts.Items.Remove(cmbBx_opts.SelectedItem);
}
因此,当我开始编程时,组合框中选定的项目现在被删除,但不在文本文件中。我该怎么做??
为什么不使用.json文件或.xml文件?使用更好,更简单.. – Furtiro
我的团队和我不知道如何使用这些文件 –