哇哇
成员
- 已加入
- 2019年11月9日
- 留言内容
- 16
- 编程经验
- Beginner
是的,所以我已经尝试了几天,但我真的无法提出任何建议,仅凭纯粹的基础知识。
我要做的就是在用户单击comboBox并取消订阅事件时生成comboBox.Items,因此我不仅会得到很多上述项目的副本。从那里开始,我需要这样做,以便当他们选择这些项目中的任何一项时,与他们相关的数据都将被加载到dataGridview中,而我被卡在这里。文件中的数据采用以下格式:项目名称:其尺寸,剩余量:尺寸,数量:尺寸,数量:...等。发生什么事,我从3个不同的项目数据中加载数据,而不是从我需要的不同维度或数量中加载数据。
如果可以的话,请使代码或任何技术性内容保持简单,以便我理解。谢谢。
C#:
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 WindowsFormsApp2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void comboBox1_Click(object sender, EventArgs e)
{
string filePath = System.IO.Directory.GetCurrentDirectory() + @"\txt1.txt";
using (var streamReader = new System.IO.StreamReader(filePath))
{
while (!streamReader.EndOfStream)
{
string line = streamReader.ReadLine();
string[] index = line.Split('\t');
for(int i=0; i<index.Length; i++)
{
string[] prekPav = index[i].Split(':');
comboBox1.Items.Add(prekPav[i]);
comboBox1.Click -= comboBox1_Click;
}
}
}
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
string filePath = System.IO.Directory.GetCurrentDirectory() + @"\txt1.txt";
using (var streamReader = new System.IO.StreamReader(filePath))
{
while (!streamReader.EndOfStream)
{
string line = streamReader.ReadLine();
string[] index = line.Split('\t');
for (int i = 0; i < index.Length; i++)
{
string[] prek = index[i].Split(':');
string[] mat = prek[i+1].Split(',');
string[] kiek = prek[i+1].Split(':');
kiek[i] = kiek[i].Replace(mat[i] + ",", "");
}
}
}
}
}
}
如果可以的话,请使代码或任何技术性内容保持简单,以便我理解。谢谢。