打印班级信息C#表格

打印班级信息C#表格,c#,forms,C#,Forms,我正试图制作一个程序,将一个国家类别中的一组国家信息存储在AVL树中。我正在使用一个表格打印保存在CSV文件中的国家列表,当我单击某个国家时,我希望程序打印与所选国家相对应的信息 我遇到的问题是,当我在列表框中选择一个国家时,让它在文本框中打印GDP 我可以在列表框中输入什么代码,将gdp打印到文本框中 private void listBox1_SelectedIndexChanged(object sender, EventArgs e) {

我正试图制作一个程序,将一个国家类别中的一组国家信息存储在AVL树中。我正在使用一个表格打印保存在CSV文件中的国家列表,当我单击某个国家时,我希望程序打印与所选国家相对应的信息

我遇到的问题是,当我在列表框中选择一个国家时,让它在文本框中打印GDP

我可以在列表框中输入什么代码,将gdp打印到文本框中

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            Country country = (Country)listBox1.SelectedValue;

        }

名称空间国家
{
公共部分类Form1:Form
{
AVLTree myTree=新的AVLTree();
列表国家=新列表();
静态字符串[]头=新字符串[6];
字符串缓冲区=”;
公共表格1()
{
初始化组件();
const int MAX_line_FILE=50000;
string[]AllLines=新字符串[MAX_LINES_FILE];
AllLines=File.ReadAllLines(“countries.CSV”);
foreach(所有行中的字符串行)
{
如果(第行起始于(“国家”))
{
headers=line.Split(',');
}
其他的
{
string[]columns=line.Split(',');
LinkedList tradePartner=新LinkedList();
字符串[]partners=columns[5]。拆分(“;”、“[”、“]”);
foreach(伙伴中的字符串x)
{
如果(x!=“”)
{
贸易伙伴。AddLast(x);
}
}
myTree.InsertItem(新国家(列[0]、float.Parse(列[1])、float.Parse(列[2])、float.Parse(列[3])、float.Parse(列[4])、tradePartner);
}
}
myTree.PreOrder(ref缓冲区);
Console.WriteLine(“树包含”+缓冲区);
添加();
}
私有void Add()
{
myTree.CInOrder(参考国家);
foreach(国家/地区中的国家/地区y)
{
列表框1.Items.Add(y.Countryname);
}
}
私有无效列表框1\u SelectedIndexChanged(对象发送方,事件参数e)
{
国家/地区=(国家/地区)列表框1.SelectedValue;
}
私有void textBox1\u TextChanged(对象发送方,事件参数e)
{
}
私有void textBox2_TextChanged(对象发送方,事件参数e)
{
}
}
}
国家级

    public Country (string cn, float gd, float i, float tb, float hd, LinkedList<string> mt)
    {
        this.Countryname = cn;
        this.gdp = gd;
        this.inflation = i;
        this.tradeBalance = tb;
        this.hdi = hd;
        this.mtp = mt;
    }

    public int CompareTo(object other)
    {
        Country temp = (Country)other;
        return Countryname.CompareTo(temp.Countryname);
    }

    public override string ToString()
    {
        foreach (string i in mtp)
            x += i + ",";
        return Countryname + " " + gdp + " " + inflation + " " + tradeBalance +" " + hdi + " " + x;


    }





}
公共国家(字符串cn、浮点gd、浮点i、浮点tb、浮点hd、LinkedList mt)
{
this.Countryname=cn;
这是gdp=gd;
这是通货膨胀=i;
这个.贸易平衡=tb;
this.hdi=hd;
这个.mtp=mt;
}
公共整数比较(对象其他)
{
国家温度=(国家)其他;
返回Countryname.CompareTo(临时Countryname);
}
公共重写字符串ToString()
{
foreach(mtp中的字符串i)
x+=i+“,”;
返回Countryname+“”+gdp+“”+通货膨胀+“”+tradeBalance+“”+hdi+“”+x;
}
}

是否需要所有这些代码来解释您的问题?可能不需要,但越多越好?当然不需要-最小值越好。对于OP不认为提供有用的情况,有一个特殊的接近投票的原因……我按照他们的思路输入了一些东西,但我不断得到一个错误“由于其保护级别而无法访问”使变量公开(gdp)
    public Country (string cn, float gd, float i, float tb, float hd, LinkedList<string> mt)
    {
        this.Countryname = cn;
        this.gdp = gd;
        this.inflation = i;
        this.tradeBalance = tb;
        this.hdi = hd;
        this.mtp = mt;
    }

    public int CompareTo(object other)
    {
        Country temp = (Country)other;
        return Countryname.CompareTo(temp.Countryname);
    }

    public override string ToString()
    {
        foreach (string i in mtp)
            x += i + ",";
        return Countryname + " " + gdp + " " + inflation + " " + tradeBalance +" " + hdi + " " + x;


    }





}
    private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
    {
        Country country = (Country)listBox1.SelectedValue;
        if (country != null ) 
           textBox1.Text = country.gdp;
    }