Visual C#:列表框清除项目的问题 [英] Visual C# : listbox clearing item's issue
问题描述
我最近正在学习listbox的基础知识,直到现在我已经学到了这些东西:
TextBox1
button1
button2
ListBox1
并且我编写了以下代码:
I''m learning the basics of listbox recently, and til now I''ve learned these things:
TextBox1
button1
button2
ListBox1
and I''ve written the following code:
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 listbox_test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//the add button
private void button1_Click(object sender, EventArgs e)
{
listBox1.Items.Add(textBox1.Text);
}
//the clear button
private void button2_Click(object sender, EventArgs e)
{
listBox1.Items.Clear();
}
}
}
该程序可以正常运行;事实是,当我按下button2时,列表框中的全名将被删除.
-1-
我想知道如何更改它并使其仅删除输入的最后一个字符串(后入)
有可能吗?
为了进行确认,除了列表框之外,还有其他灵活的对象吗?
-2-
我可以选择我想要的字符串,然后按清除"以清除它吗?
这部分我觉得它更合适,即使最后一件事让我头疼,因为我真的很无能为力."
所以,您能帮我忙吗?
the program works completely fine; the thing is, when I press button2, the whole names in the listbox will be deleted.
-1-
I wonder how could I change it and make it only delete the last string entered (last-in)
is it possible?
and for acknowledgement, is there any other flexible object rather than the listbox?
-2-
can I just select a string I want and then just press on "clear" to clear it
"this part I find it more suitable, even though the last in thing gives me a headache because I''m really clueless "
so, can you give me your hand, mate?
推荐答案
仅阅读控件System.Windows.Forms.ListBox
上的MSDN帮助有什么问题: http://msdn.microsoft.com/en-us/library/system.windows.forms .listbox.aspx [ ^ ]?
您所有的问题都无需查看代码,只需查看System.Windows.Forms.ListBox.Items
以及该属性的类的属性即可回答:Clear
,Remove
和RemoveAt
.
祝你好运,
—SA
What''s wrong with simply reading of the MSDN help on the controlSystem.Windows.Forms.ListBox
: http://msdn.microsoft.com/en-us/library/system.windows.forms.listbox.aspx[^]?
All your questions do not need a look at your code and are answered by looking atSystem.Windows.Forms.ListBox.Items
and the properties of the class of this property:Clear
,Remove
andRemoveAt
.
Good luck,
—SA
这篇关于Visual C#:列表框清除项目的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!