Click here to Skip to main content
15,927,946 members
Home / Discussions / C#
   

C#

 
GeneralExport DataGrid to Excel Pin
maximusus20-Sep-04 14:58
maximusus20-Sep-04 14:58 
GeneralRe: Export DataGrid to Excel Pin
Christian Graus20-Sep-04 15:59
protectorChristian Graus20-Sep-04 15:59 
GeneralRe: Export DataGrid to Excel Pin
sreejith ss nair20-Sep-04 20:06
sreejith ss nair20-Sep-04 20:06 
QuestionDragging the image in RichTextBox ? Pin
sachinkalse20-Sep-04 14:55
sachinkalse20-Sep-04 14:55 
AnswerRe: Dragging the image in RichTextBox ? Pin
bekunkun20-Sep-04 23:21
bekunkun20-Sep-04 23:21 
GeneralRe: Dragging the image in RichTextBox ? Pin
sachinkalse21-Sep-04 14:43
sachinkalse21-Sep-04 14:43 
QuestionCopy Paste from ListView? Pin
Delegate20-Sep-04 11:14
Delegate20-Sep-04 11:14 
AnswerRe: Copy Paste from ListView? Pin
Heath Stewart20-Sep-04 14:07
protectorHeath Stewart20-Sep-04 14:07 
Handling key strokes is the easy part. Handle the ListView.KeyUp event and check the KeyEventArgs.KeyCode and KeyEventArgs.Control properties:
listView1.KeyUp += new KeyEventHandler(OnKeyUp);
// ...
private void OnKeyUp(object sender, KeyEventArgs e)
{
  if (e.Control)
  {
    if (e.KeyCode == Keys.C) Copy();
    else if (e.KeyCode == Keys.P) Paste();
  }
}
To copy, grab the selected ListViewItems, pack them in a DataObject, and send to the clipboard. Note that this will only work within the same AppDomain:
public void Copy()
{
  DataObject do = new DataObject("ListViewItems", listView1.SelectedItems);
  Clipboard.SetDataObject(do, false);
}
To paste, you unpack the copied data (if relevent) and insert into the ListView:
public void Paste()
{
  IDataObject do = Clipboard.GetDataObject();
  if (do != null)
  {
    IEnumerable items = (IEnumerable)do.GetData("ListViewItems");
    if (items != null)
      foreach (ListViewItem item in items)
        listView1.Items.Add(item);
  }
}
Note that this code is untested but should give you a start of what you need to do. Implementing drag and drop is not much different.

Again, remember that this will only work within an AppDomain. To copy and paste ListViewItems between two separate AppDomains (ex: two different instances of a Windows Forms application), you need to marshal the data. You could marshal it as a string (encode the selected ListViewItems as a string, then decode it in the other AppDomain), or a number of other things that would be difficult to do in a managed application (like alloc'ing the items in global memory, though with objects tied to a HANDLE (native pointer) that isn't so easy).

This posting is provided "AS IS" with no warranties, and confers no rights.

Software Design Engineer
Developer Division Sustained Engineering
Microsoft

[My Articles]
GeneralIE Toolband Pin
Matt Newman20-Sep-04 10:34
Matt Newman20-Sep-04 10:34 
GeneralRe: IE Toolband Pin
Judah Gabriel Himango20-Sep-04 10:55
sponsorJudah Gabriel Himango20-Sep-04 10:55 
GeneralRe: IE Toolband Pin
Anonymous20-Sep-04 11:06
Anonymous20-Sep-04 11:06 
QuestionBittorrent client in C#? Pin
Marlun20-Sep-04 9:08
Marlun20-Sep-04 9:08 
AnswerRe: Bittorrent client in C#? Pin
Steven Campbell20-Sep-04 10:30
Steven Campbell20-Sep-04 10:30 
GeneralRe: Bittorrent client in C#? Pin
Marlun21-Sep-04 19:32
Marlun21-Sep-04 19:32 
GeneralDataGrid Sorting Problem using a DataSet from ViewState Pin
veroBT20-Sep-04 7:37
veroBT20-Sep-04 7:37 
GeneralRe: DataGrid Sorting Problem using a DataSet from ViewState Pin
Heath Stewart20-Sep-04 13:54
protectorHeath Stewart20-Sep-04 13:54 
GeneralC# and org.apache.log4j.PropertyConfigurator Pin
devvvy20-Sep-04 4:22
devvvy20-Sep-04 4:22 
GeneralRe: C# and org.apache.log4j.PropertyConfigurator Pin
Heath Stewart20-Sep-04 6:46
protectorHeath Stewart20-Sep-04 6:46 
GeneralRe: C# and org.apache.log4j.PropertyConfigurator Pin
Steven Campbell20-Sep-04 7:06
Steven Campbell20-Sep-04 7:06 
GeneralRe: C# and org.apache.log4j.PropertyConfigurator Pin
Heath Stewart20-Sep-04 7:11
protectorHeath Stewart20-Sep-04 7:11 
GeneralRe: C# and org.apache.log4j.PropertyConfigurator Pin
devvvy21-Sep-04 7:53
devvvy21-Sep-04 7:53 
GeneralRe: C# and org.apache.log4j.PropertyConfigurator Pin
devvvy21-Sep-04 7:52
devvvy21-Sep-04 7:52 
GeneralRe: C# and org.apache.log4j.PropertyConfigurator Pin
Heath Stewart21-Sep-04 11:01
protectorHeath Stewart21-Sep-04 11:01 
GeneralRe: C# and org.apache.log4j.PropertyConfigurator Pin
devvvy22-Sep-04 17:26
devvvy22-Sep-04 17:26 
GeneralRe: C# and org.apache.log4j.PropertyConfigurator Pin
Heath Stewart22-Sep-04 20:21
protectorHeath Stewart22-Sep-04 20:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.