我已經初始化的書籍以下ArrayList的,我可以遍歷搜索項目:在一個ArrayList
public void InitializeArrayList()
{
list.Add(new Books("Pride and Prejudice", "Jane Austen", "Romance", "1813"));
list.Add(new Books("The Notebook", "Nicholas Sparks", "Romance", "1996"));
list.Add(new Books("Carrie", "Stephen King", "Horror", "1974"));
list.Add(new Books("The Shining", "Stephen King", "Horror", "1977"));
list.Add(new Books("A Game of Thrones", "George R.R. Martin", "Fantasy", "1996"));
list.Add(new Books("A Clash of Kings", "George R.R. Martin", "Fantasy", "1998"));
list.Add(new Books("A Storm of Swords", "George R.R. Martin", "Fantasy", "2000"));
list.Add(new Books("A Feast for Crows", "George R.R. Martin", "Fantasy", "2005"));
list.Add(new Books("A Dance with Dragons", "George R.R. Martin", "Fantasy", "2011"));
list.Add(new Books("Gone Girl", "Gillian Flynn", "Thriller", "2014"));
list.Add(new Books("The Girl on the Train", "Paula Hawkins", "Thriller", "2015"));
list.Add(new Books("The Hunger Games", "Suzanne Collins", "Science Fiction", "2008"));
list.Add(new Books("Catching Fire", "Suzanne Collins", "Science Fiction", "2009"));
list.Add(new Books("Mockingjay", "Suzanne Collins", "Science Fiction", "2010"));
list.Add(new Books("Matilda", "Roald Dahl", "Children's Fiction", "1988"));
list.Add(new Books("Charlie and the Chocolate Factory", "Roald Dahl", "Children's Fiction", "1964"));
list.Add(new Books("Room", "Emma Donoghue", "Fiction", "2010"));
list.Add(new Books("Holes", "Louis Sachar", "Fiction", "1998"));
list.Add(new Books("About a Boy", "Nick Hornby", "Fiction", "1998"));
}
我想打一個搜索按鈕,這樣我可以輸入書名,當我按下搜索它會發送給我一個新的表格,包含在該書中的所有細節,包含在數組中(標題,作者,流派)。
這是我嘗試迄今:
private void button3_Click(object sender, EventArgs e)
{
String match = textbox.Text;
foreach (Object b in list)
{
Books book = (Books)b;
if (book.Equals(match))
{
Form2 form = new Form2();
form.Visible = true;
}
}
}
基本上,我不知道如何使它發送到新的形式與所有這些細節?
什麼是你的問題的一個簡單的方法? – Blorgbeard