我有16个项目在listBox1和一个按钮“button1”,我需要能够将选定的项目从listBox1移动到listBox2时按下按钮。目前我的代码是如何添加选定的项目从一个列表框到另一个列表框
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;
using System.Xml;
using System.IO;
namespace courseworkmodule
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
String workingDir = Directory.GetCurrentDirectory();
XmlTextReader textReader = new XmlTextReader(workingDir + @"\modules.xml");
Console.WriteLine("BaseURI:" + textReader.BaseURI);
textReader.Read();
while (textReader.Read())
{
textReader.MoveToElement();
if (textReader.Name == "Name")
{
textReader.Read();
XmlNodeType nType = textReader.NodeType;
if (nType == XmlNodeType.Text)
{
listBoxAllModules.Items.Add(textReader.Value);
}
}
}
Console.ReadLine();
textReader.Close();
}
public void button1_Click(object sender, EventArgs e)
{
listBoxStudentModules.Items.Add(listBoxAllModules.SelectedItem);
}
private void Form1_Load_1(object sender, EventArgs e)
{
}
private void listBoxAllModules_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
}
其中listBoxAllModule是listBox1中和listBoxStudentModule是listBox2 在此先感谢您的帮助
代码有什么问题?它抛出一些错误? – Shyju 2012-03-31 00:37:48
另外,当你说“移动”时,你的意思是你想删除从listboxallmodules中选择的条目吗? – Rich 2012-03-31 00:45:00
它抛出错误的“项目”,如“错误:非可调用成员'System.Windows.Forms.ListBox.Items'不能像方法一样使用” – 2012-03-31 00:46:16