How to implement drag and drop between excel and C# ListView  
Author Message
Lixin wang





PostPosted: Visual C# General, How to implement drag and drop between excel and C# ListView Top

Hi,

Does anyone know how to implement drag and drop between excel and ListView in C# Drag and drop a single string is easy. But i don't know how to drag and drop a group of cells.

Thanks

Lee




Visual C#9  
 
 
solardog





PostPosted: Visual C# General, How to implement drag and drop between excel and C# ListView Top

I am trying to do the same in reverse. Could you send me information on what you've done. Perhaps we can figure this out together.


 
 
Lee Wang





PostPosted: Visual C# General, How to implement drag and drop between excel and C# ListView Top

I find out the solution and done this way:

MemoryStream stream = new MemoryStream();

StreamWriter writer = new StreamWriter(stream);

int columnCount = listView1.Columns.Count;

for (int i = 0; i < columnCount; i++)

{

writer.Write(listView1.ColumnsIdea.Text);

if (i+1 < columnCount) writer.Write("\t");

}

writer.WriteLine();

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

{

for (int i = 0; i < listView1.Items[j].SubItems.Count; i++)

{

writer.Write( listView1.Items[j].SubItemsIdea.Text);

if (i+1 < listView1.Items[j].SubItems.Count)

writer.Write("\t");

}

writer.WriteLine();

}

writer.Flush();

writer.Close();

byte[] buffer = stream.GetBuffer();

stream.Close();

System.Text.Encoding _encoding =new System.Text.UTF8Encoding();

string tabData = _encoding.GetString(buffer, 0, buffer.Length);

this.listView1.DoDragDrop(tabData, DragDropEffects.Copy);