hi.
any one can please tell me how can i show my obejct"each" in my new point.....
new point it bellow....
this.listView2.View = View.LargeIcon;
ListViewItem item = e.Data.GetData(typeof(ListViewItem)) as ListViewItem;
object[] array = new object[listView1.SelectedItems.Count];
listView1.SelectedItems.CopyTo(array, 0);
foreach(object each in array)
{
Point pt = this.listView2.PointToClient(new Point(e.X, e.Y));
" Over Here "= this.listView2.GetItemAt(pt.X, pt.Y);
}
any way i need to display my item in new point.....
i need every body's help.....its urgent....im stuck.....
thanks a lot u all....
asela WijesooriyaPosted Mar 1, 2009, 5:25 AM
jan it didn't work....do u know y??
any idea???
Jan MontanoPosted Feb 25, 2009, 8:00 PM
I did a google search for c# drag and drop listview. I got this article from c-sharpcorner.
Implementing Drag and Drop in ListView Controls.
I guess this is all you'll need for your requirement. Try to make the article work first on a different project.
Here's an additional listview drag and drop article from Microsoft.
*Edit oops the fonts got big, weird.
asela WijesooriyaPosted Feb 24, 2009, 9:24 PM
hi,
ill tell u whole thin what im trying to do here....
i got listViewBox (A)
inside that i got some listview Items. i need to drag and drop certain items from that to another listViewBox(B). how can i do that....
i tried to use foreach loop to focus each and every item that i selected....
and do to all selected items,what ever is do to a item.....
can u pl tell me how can i do this drag drop....
ill post my codes....take a look....
and thanks a lot for ur BIG BIG BIG HELP......BIG MAC 4 u....thanks
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, 100);
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));
}
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 Image getThumbnaiImage(int width, Image img)
{
Image thumb = new Bitmap(width, width);
Image tmp = null;
//If the original image is small than the Thumbnail size, just draw in the center
if (img.Width < width && img.Height < width)
{
using (Graphics g = Graphics.FromImage(thumb))
{
int xoffset = (int)((width - img.Width) / 2);
int yoffset = (int)((width - img.Height) / 2);
g.DrawImage(img, xoffset, yoffset, img.Width, img.Height);
}
}
else //Otherwise we have to get the thumbnail for drawing
{
Image.GetThumbnailImageAbort myCallback = new
Image.GetThumbnailImageAbort(ThumbnailCallback);
if (img.Width == img.Height)
{
thumb = img.GetThumbnailImage(
width, width,
myCallback, IntPtr.Zero);
}
else
{
int k = 0;
int xoffset = 0;
int yoffset = 0;
if (img.Width < img.Height)
{
k = (int)(width * img.Width / img.Height);
tmp = img.GetThumbnailImage(k, width, myCallback, IntPtr.Zero);
xoffset = (int)((width - k) / 2);
}
if (img.Width > img.Height)
{
k = (int)(width * img.Height / img.Width);
tmp = img.GetThumbnailImage(width, k, myCallback, IntPtr.Zero);
yoffset = (int)((width - k) / 2);
}
using (Graphics g = Graphics.FromImage(thumb))
{
g.DrawImage(tmp, xoffset, yoffset, tmp.Width, tmp.Height);
}
}
}
using (Graphics g = Graphics.FromImage(thumb))
{
g.DrawRectangle(Pens.Green, 0, 0, thumb.Width - 1, thumb.Height - 1);
}
return thumb;
}
public bool ThumbnailCallback()
{
return true;
}
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 btnsave_Click_1(object sender, EventArgs e)
{/*
try
{
saveFileDialog1.Filter="*.jpg|*.jpg|*.bmp|*.bmp|*.gif|*.gif";
saveFileDialog1.ShowDialog();
if(saveFileDialog1.FileName != "")
{
System.IO.FileStream fs =
(System.IO.FileStream)saveFileDialog1.OpenFile();
switch(saveFileDialog1.FilterIndex)
{
/* case 1 :
this.listView2.dataepictureBox1.Image.Save(fs,
System.Drawing.Imaging.ImageFormat.Jpeg);
break;
case 2 :
this.pictureBox1.Image.Save(fs,
System.Drawing.Imaging.ImageFormat.Bmp);
break;
case 3 :
this.pictureBox1.Image.Save(fs,
System.Drawing.Imaging.ImageFormat.Gif);
break;
}
fs.Close();
}
}
catch
{
MessageBox.Show("there is no Pic selected please select a Pic first","Dear "+ System.Environment.UserDomainName);
}*/
}
private void listView1_ItemDrag(object sender, ItemDragEventArgs e)
{
this.listView1.DoDragDrop(this.listView1.SelectedItems[0], DragDropEffects.Copy);
}
private void listView1_DragDrop(object sender, DragEventArgs e)
{
ListViewItem item = e.Data.GetData(typeof(ListViewItem)) as ListViewItem;
object[] array = new object[listView2.SelectedItems.Count];
listView2.SelectedItems.CopyTo(array, 0);
//string s = array;
this.listView1.Items.Add("array");
this.listView2.Items.RemoveAt(listView1.SelectedItems.IndexOf(item));
}
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_ItemDrag(object sender, ItemDragEventArgs e)
{
this.listView2.DoDragDrop(this.listView2.SelectedItems[0], DragDropEffects.Copy);
}
private void listView2_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(ListViewItem)))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
Jan MontanoPosted Feb 24, 2009, 6:49 PM
what is your goal here?
asela WijesooriyaPosted Feb 24, 2009, 9:02 AM
actualy i tried this
ListViewItem item = this.listView2.GetItemAt(pt.X, pt.Y);
problem was couldn't get the image.my listview items consists of images......i mean i do drag drop over here from another list view box...that list view box containt images as itemlist
Jan MontanoPosted Feb 24, 2009, 12:30 AM
I'm assuming this is related to this thread.
It may be that you don't need those calls, which brings me down to this question. What do you want to accomplish here? Without explaining the code, what do you want to happen?
There's a chance that we could use a more simple code with your requirement just like with the other thread.
Regards,
Jan
Jan MontanoPosted Feb 24, 2009, 12:22 AM
" Over Here "= this.listView2.GetItemAt(pt.X, pt.Y);
ListViewItem item = this.listView2.GetItemAt(pt.X, pt.Y);