在搜索功能中搜索的项目:ALBUMS没有添加到列表框中? 其他字段填充
你能告诉我如何用搜索到的专辑填充列表框 使用链接列表查找相册
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Assignment
{
public partial class frmAddArtist : Form
{
AVLTree<Artist> avltree = new AVLTree<Artist>();
LinkedList<Album> temp = new LinkedList<Album>();
Artist artistinst;
Album albuminst;
string noofmembers, artistname;
int artistcount;
public frmAddArtist()
{
InitializeComponent();
}
private void label5_Click(object sender, EventArgs e)
{
}
private void btnAddArtist_Click(object sender, EventArgs e)
{
string tempalbum, date;
tempalbum = txtAlbumName.Text;
date = dtpReleaseDate.Text.ToString();
albuminst = new Album(tempalbum, date);
temp.AddFirst(albuminst);
lbAlbums.Items.Add(tempalbum);
}
private void btnSave_Click(object sender, EventArgs e)
{
artistname = txtArtistName.Text;
noofmembers = txtNoOfMembers.Text;
artistinst = new Artist(artistname, noofmembers, temp);
avltree.InsertItem(artistinst);
artistcount++;
txtArtistName.Clear();
txtNoOfMembers.Clear();
txtAlbumName.Clear();
lbAlbums.Items.Clear();
temp.Clear();
}
private void btnNoOfArtist_Click(object sender, EventArgs e)
{
MessageBox.Show("The No. Artist: " + Convert.ToString(artistcount));
}
private void btnHeight_Click(object sender, EventArgs e)
{
int heightoftree = avltree.Height();
string height = Convert.ToString(heightoftree);
MessageBox.Show("The Height of the Tree: " + height);
}
private void btnSearch_Click(object sender, EventArgs e)
{
Artist temp = new Artist(txtSearch.Text, " ", null);
Artist result = avltree.Search(temp);
if (result != null)
{
if (result.CompareTo(temp) == 0)
{
txtArtistName.Text = result.artistname;
txtNoOfMembers.Text = result.noofmembers;
foreach (Album p in result.Albumslist)
{
lbAlbums.Items.Add(p.Albumname);
}
}
else if(result.CompareTo(temp) <0)
{
MessageBox .Show("No Match Found");
}
}
}
}
}
答案 0 :(得分:0)
将项目放入LinkedList或List。 然后设置lbAlbums.ItemsSource =;