所以我能夠通過索引刪除,但我的問題是否有辦法通過鍵入對象名稱來刪除對象?例如:鍵入sara按鈕,它從我的索引中刪除該對象。 我的第二個問題是有沒有一種方法可以將一個新的對象插入到我想要的索引中?操縱索引中的對象
我在Windows窗體中,如果你能幫助我或鏈接我的教程我會非常感激。
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
object[] names={"Sara", "Bill", "Martin", "Suasan", "Don"};
listBox1.Items.AddRange(names);
}
private void btnRemoveByIndex_Click(object sender, EventArgs e)
{
//remove by index
int index = int.Parse(txtIndex.Text);
if (index >= 0 && index < listBox1.Items.Count)
{
listBox1.Items.RemoveAt(index);
}
listBox1.ClearSelected();
}
private void btnRemoveByItem_Click(object sender, EventArgs e)
{
//remove objects
}
private void btnSpecIndex_Click(object sender, EventArgs e)
{
//insert new object
}
似乎並沒有做任何事情 – TheBoringGuy
Nvm讀它錯了大聲笑 – TheBoringGuy