如何在列表框中显示信息?

时间:2016-11-28 00:28:36

标签: c# listbox

我从昨天起开始研究这个程序,但我无法理解我在哪里做错了。如果你能帮助我,我真的很感激。问题是当我试图点击查看按钮查看列表框中的信息不显示信息。

   // Saving Artist
    public void saveArtist()
    {
        using (StreamWriter sw = new StreamWriter("Artist.txt"))
        {
            for (int i = 0; i < artistlist.Count; i++)
            {
                sw.WriteLine( artistlist[i].ID + " ; " + artistlist[i].NAME + ", " + curatorlist[i].ID);

            }
        }
    }

 // Add Artist
    private void AddArtistButton_Click(object sender, RoutedEventArgs e)
    {
        //Asking the user to enter artist ID and checking if it is exist or not
        Artist artist = new Artist();
        try
        {
            artist.ID = ArtistIDArt.Text;
            bool Exist = false;
            for (int i = 0; i < artistlist.Count; i++)
            {
                if (artistlist[i].ID == artist.ID)
                {
                    Exist = true;
                    break;
                }
            }
            if (Exist)
            {
                MessageBox.Show("ID already exist please try again !");
                return;
            }

        }

        catch (Exception Error)
        {
            MessageBox.Show(Error.Message);
        }
        // asking the user to enter the Artist name

        try
        {
            artist.NAME = ArtistNameArt.Text;
        }

        catch (Exception Error)
        {
            MessageBox.Show(Error.Message);
        }
        // Asking the user to enter to Curator ID and checking if its matching or not 
        try
        {

            artist.curator_id = CuratorIDArt.Text;
            //checking if the ID is Exist or not
            bool sameid = false;

            for (int i = 0; i < curatorlist.Count; i++)
            {
                if (curatorlist[i].ID == artist.curator_id)
                {
                    sameid = true;
                }
            }// if the ID Does not Exist the user will get a message Saying " ID does not match!".
            if (sameid == false)
            {
                MessageBox.Show(" ID does not match!");
                return;
            }

            else
            {
                // if the ID  Exist the user will get a message Saying " Your ID Found and  accpted succesfully!"".

                MessageBox.Show(" Your ID Found and  accpted succesfully!");

            }

            artistlist.Add(artist);
            saveArtist();

            CuratorIDArt.Clear();
            ArtistIDArt.Clear();
            ArtistNameArt.Clear();

        }
        catch (Exception error)
        {
            MessageBox.Show(error.Message);
        }
    }
      // View Artist
    private void ViewArtist(object sender, RoutedEventArgs e)
    {
        StreamReader Artistread = new StreamReader("Artist.txt");
        String Printart;
        while ((Printart = Artistread.ReadLine()) != null)
        {
            string[] list = Printart.Split(';');

            ListBoxArtistView.Items.Add("ID:" + list[0] + "The Artist name: " + list[1] + "Curator ID :" + list[2] + "\r\n");

            // ViewCuratorIDBox.Clear();
        }
        Artistread.Close();
    }

0 个答案:

没有答案