我已经在list里添加了学生的基本信息,并在listbox显示出来,能不能根据学号,为此学生添加成绩信息在listbox中显示呢?
求各位大神解惑,谢谢~
可以,看下面
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Q712947
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
for (int i = 0; i < 5; i++)
listBox1.Items.Add(i);
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (listBox1.SelectedIndex > 0)
{
textBox1.Text = listBox1.SelectedIndex.ToString();
textBox2.Text = listBox1.Items[listBox1.SelectedIndex].ToString();
}
}
private void button1_Click(object sender, EventArgs e)
{
listBox1.Items[int.Parse(textBox1.Text)] = textBox2.Text;
}
}
}