private void MovieSoldDrop(object sender, DragEventArgs e)
        {
            object       o = e.Data.GetData(DataFormats.Serializable);
            ListViewItem l = (ListViewItem)o;

            DialogResult dr = MessageBox.Show("Are you sure you want to sell " +
                                              l.Text + "?",
                                              "Sell This Video",
                                              MessageBoxButtons.YesNo);

            if (dr == DialogResult.No)
            {
                return;
            }

            //Very important!!  If I did not remove this ListViewItem from the source
            //list I would need to clone this ListViewItem before I add it to the
            //lstSold control.
            lstRentals.Items.Remove(l);
            lstSold.Items.Add((ListViewItem)l);
            lstSold.Items[lstSold.Items.Count - 1].ImageIndex = 0;

            //Look at the genre combo box to see which movie list to delete this
            //ListViewItem from.
            MovieList m = (MovieList)cmbGenre.SelectedItem;

            m.Remove(l);
        }
 private void GetList(MovieList list)
 {
     lstRentals.BeginUpdate();
     lstRentals.Items.Clear();
     lstRentals.Items.AddRange(list.Items);
     lstRentals.EndUpdate();
 }
        private void RentalCartDrop(object sender, DragEventArgs e)
        {
            object       o = e.Data.GetData(DataFormats.Serializable);
            ListViewItem l = (ListViewItem)o;

            DialogResult dr = MessageBox.Show("Confirm Rental of " + l.Text,
                                              "Rent Video",
                                              MessageBoxButtons.YesNo);

            if (dr == DialogResult.No)
            {
                return;
            }

            //Look at the genre combo box to see which movie list to delete this
            //ListViewItem from.
            MovieList m = (MovieList)cmbGenre.SelectedItem;

            if (!m.CheckOut(l))
            {
                MessageBox.Show("This Movie is already out.");
            }
        }
        public Form1()
        {
            InitializeComponent();

            //Get the movie ListViewItems
            try   { ActionMovies = new MovieList("ActionMovies.txt"); }
            catch { ActionMovies = null; }

            try   { DramaMovies = new MovieList("DramaMovies.txt"); }
            catch { DramaMovies = null; }

            try   { ComedyMovies = new MovieList("ComedyMovies.txt"); }
            catch { ComedyMovies = null; }

            //Set up the rental ListView
            lstRentals.View = View.Details;
            lstRentals.AllowColumnReorder = true;
            lstRentals.GridLines          = true;
            lstRentals.FullRowSelect      = true;
            lstRentals.AllowDrop          = true;
            lstRentals.ItemDrag          += new ItemDragEventHandler(this.MovieRentalStartDrag);
            lstRentals.DragEnter         += new DragEventHandler(this.MovieRentalDragAcross);
            lstRentals.Columns.Add("Title", -2, HorizontalAlignment.Center);
            lstRentals.Columns.Add("Release Date", -2, HorizontalAlignment.Center);
            lstRentals.Columns.Add("Running Time", -2, HorizontalAlignment.Center);
            lstRentals.Columns.Add("Format", -2, HorizontalAlignment.Center);
            lstRentals.Columns.Add("In Stock", -2, HorizontalAlignment.Center);

            //Make something that will hold the current sort order for the current column
            ArrayList order = new ArrayList();

            for (int k = 0; k < lstRentals.Columns.Count; k++)
            {
                order.Insert(k, SortOrder.Ascending);
            }
            order.TrimToSize();
            lstRentals.Tag          = order;
            lstRentals.ColumnClick += new ColumnClickEventHandler(ColumnSort);

            //Now set up the For-Sale ListView
            BigIcons = new ImageList();
            BigIcons.Images.Add(Image.FromFile("movie.bmp"));
            lstSold.LargeImageList = BigIcons;
            lstSold.View           = View.LargeIcon;
            lstSold.AllowDrop      = true;
            lstSold.DragEnter     += new DragEventHandler(MovieDragInto);
            lstSold.DragDrop      += new DragEventHandler(MovieSoldDrop);

            //Fill the rental box
            picRental.SizeMode   = PictureBoxSizeMode.StretchImage;
            picRental.Image      = Image.FromFile("cart.bmp");
            picRental.AllowDrop  = true;
            picRental.DragEnter += new DragEventHandler(MovieDragInto);
            picRental.DragDrop  += new DragEventHandler(this.RentalCartDrop);

            //Fill the ComboBox.  This MUST be done after setting up the
            //rental listView control
            if (ActionMovies != null)
            {
                cmbGenre.Items.Add(ActionMovies);
            }
            if (DramaMovies != null)
            {
                cmbGenre.Items.Add(DramaMovies);
            }
            if (ComedyMovies != null)
            {
                cmbGenre.Items.Add(ComedyMovies);
            }
            cmbGenre.SelectedIndexChanged += new EventHandler(this.GenreClick);
            //Setting the index automatically fires the event
            cmbGenre.SelectedIndex = 0;
        }