将组合框中的项目添加到Listview并开始在ListView中执行项目

时间:2017-03-23 14:45:50

标签: c# listview button

为了更好地解释,这里是一个GUI屏幕截图:

enter image description here

这是我的所有代码和评论:

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;
using System.Media; // to play sounds


namespace Music_PLayer
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            //List View
            listView1.View = View.Details;
            listView1.FullRowSelect = true;

            // Columns CONSTRUCT
            listView1.Columns.Add("ID", 70);
            listView1.Columns.Add("Music name", 150);

            //combobox  items
            comboBox1.Items.Add("Music 1");
            comboBox1.Items.Add("Music 2");
            comboBox1.Items.Add("Music 3");
            comboBox1.Items.Add("Music 4");
            comboBox1.Items.Add("Music 5");
        }

        // ADD TO List VIEW
        private void add(int ID, string name_music)
        {
            string[] row = { Convert.ToString(ID), name_music };

            ListViewItem item = new ListViewItem(row);

            listView1.Items.Add(item);
        }

        //button to delete selected items in list view
        private void button_delete_selected_music_Click(object sender, EventArgs e)
        {
            try
            {
                listView1.SelectedItems[0].Remove();
            }
            catch { }

        }

        // buttton to add music to list view
        int i = 0;
        private void button_add_music_Click(object sender, EventArgs e)
        {

            add(i, comboBox1.Text);
                i++;

        }

        // button to start music
        private void button_start_music(object sender, EventArgs e)
        {

        }


        // Voids with music :
        public void playmusic1()
        {

            SoundPlayer audio = new SoundPlayer(Music_PLayer.Properties.Resources.playsound1);
            audio.Play();
        }
        public void playmusic2()
        {
            SoundPlayer audio = new SoundPlayer(Music_PLayer.Properties.Resources.playsound2);
            audio.Play();
        }
        public void playmusic3()
        {
            SoundPlayer audio = new SoundPlayer(Music_PLayer.Properties.Resources.playsound3);
            audio.Play();

        }
        public void playmusic4()
        {
            SoundPlayer audio = new SoundPlayer(Music_PLayer.Properties.Resources.playsound4);
            audio.Play();
        }
        public void playmusic5()
        {
            SoundPlayer audio = new SoundPlayer(Music_PLayer.Properties.Resources.playsound5);
            audio.Play();
        }
         public class dataItem
    {
        public string shortName { get; set; }
        public string longName { get; set; }
        public dataItem(string s, string l) { shortName = s; longName = l; }
        public override string ToString() { return shortName; }
    }


    }
}

我想从组合框中选择一首歌曲,将其添加到播放列表中,点击"开始播放音乐"播放列表将从上到下播放。按钮..

当您点击"添加音乐到列表"时,我想将组合框中的选定歌曲添加到列表视图中。按钮。当然,使用"删除所选音乐"按钮我可以从列表中删除歌曲。

所以我必须这样做,例如当我从组合框(Music1)中选择单击按钮(添加音乐到列表)时,它将显示ID 1音乐名称音乐1,当点击开始音乐按钮时它将执行void playmusic1();

我知道我只是将组合框中的文字添加到listview,但我不知道如何在那里获得方法...

我真的不知道如何编写“开始音乐”按钮以使用我的listView1逐个播放音乐。

我需要的只是收藏品或其他东西或队列。

如果我不解释,请问..

0 个答案:

没有答案