0
Answer

Drag Drop ListView ImageList Images

asela Wijesooriya

asela Wijesooriya

15y
13.5k
1

i cannot do my DRAG DROP part. tried so many code.all useless.can any one pl help me to write DRADROP part......

i tried creat another image list in listview B and add listView A imagelist selected images...but i can add item text but i cannot add the image in to new image list which i selected from list view box A imagelist images...may be this try wrong

if there any eayy way or can improve this way pl helpp me to do this....thanks a lot u all

her is my code.....

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.IO;

 

namespace Project_import_1

{

    public partial class ImportForm : Form

    {

        public ImportForm()

        {

            InitializeComponent();

        }

        OpenFileDialog dlg = new OpenFileDialog();

       

 

        private void import(object sender, EventArgs e)

        {           

            ImageList imageList = new ImageList();

            imageList.ImageSize = new Size(100, 80);

            imageList.ColorDepth = ColorDepth.Depth32Bit;

 

            int i = 0;

            string[] files = dlg.FileNames;

            string[] pathes = new string[files.Length];

 

            foreach (string file in files)

            {

                pathes[i] = file;

                i++;

            }

 

            foreach (string path in pathes)

            {

                //Image img1 = Image.FromFile(path);

                //imageList.Images.Add(getThumbnaiImage(imageList.ImageSize.Width, img1));

                imageList.Images.Add(Bitmap.FromFile(path));

                FileInfo fileInfo = new FileInfo(path);

                String strDir = fileInfo.Name;

                listView1.Items.Add(strDir);

                listView1.TileSize = new System.Drawing.Size(100, 80);

 

            }

            for (int j = 0; j < pathes.Length; j++)

            {

                //this.listView1.Items.Add("Picture"+(j+1));

                this.listView1.Items[j].ImageIndex = j;

            }

            this.listView1.View = View.LargeIcon;

            this.listView1.LargeImageList = imageList;

 

        }

private void btnImport_Click(object sender, EventArgs e)

        {

            dlg.Filter = "All Image Files|*.bmp;*.ico;*.gif;*.jpeg;*.jpg;" +

                                "*.jfif;*.png;*.tif;*.tiff;*.wmf;*.emf|" +

                         "Windows Bitmap (*.bmp)|*.bmp|" +

                         "Windows Icon (*.ico)|*.ico|" +

                         "Graphics Interchange Format (*.gif)|*.gif|" +

                         "JPEG File Interchange Format (*.jpg)|" +

                                "*.jpg;*.jpeg;*.jfif|" +

                         "Portable Network Graphics (*.png)|*.png|" +

                         "Tag Image File Format (*.tif)|*.tif;*.tiff|" +

                         "Windows Metafile (*.wmf)|*.wmf|" +

                         "Enhanced Metafile (*.emf)|*.emf|" +

                         "All Files (*.*)|*.*";

            dlg.InitialDirectory = @"C:\Documents and Settings\All Users\Desktop\";

            dlg.Multiselect = true;

 

            try

            {

                if (dlg.ShowDialog() == DialogResult.OK)

                {

                    import(sender, e);

                }

                dlg.Reset();

            }

 

            catch (Exception ex)

            {

                MessageBox.Show(ex.Message);

            }

        }

private void listView1_ItemDrag(object sender, ItemDragEventArgs e)

        {

           

            this.listView1.DoDragDrop(this.listView1.SelectedItems[0], DragDropEffects.Copy);

        }

private void listView1_DragEnter(object sender, DragEventArgs e)

        {

            if (e.Data.GetDataPresent(typeof(ListViewItem)))

            {

                e.Effect = DragDropEffects.Copy;

            }

            else

            {

                e.Effect = DragDropEffects.None;

            }

        }

private void listView2_DragDrop(object sender, DragEventArgs e)

        {

ListViewItem item = e.Data.GetData(typeof(ListViewItem)) as ListViewItem;

          

            this.listView2.View = View.LargeIcon;

            ImageList imageList = new ImageList();

            imageList.ImageSize = new Size(100, 100);

            imageList.ColorDepth = ColorDepth.Depth32Bit;

            int i = 0;

 

                    

                foreach (ListViewItem each in listView1.SelectedItems)

                {

                    listView2.Items.Add(item.Text, item.ImageIndex);

                    

                    //imageList.Images.Add(item.ImageIndex);

                    listView2.TileSize = new System.Drawing.Size(100, 80);

                }    

            for (int j = 0; j < listView1.SelectedItems.Count; j++)

            {

                this.listView1.Items[j].ImageIndex = j;              

            }

            this.listView2.View = View.LargeIcon;

            this.listView2.LargeImageList = imageList;

        }