简体   繁体   English

如何以编程方式从Excel单元格拖放到启用拖动的任务窗格?

[英]How can I drag and drop from Excel cells to a drag-enabled task pane programatically?

I am using Excel 2007, VS2008 Pro. 我正在使用Excel 2007,VS2008 Pro。 I am building a VSTO Add-in that requires "drag and drop from Excel cells to a drag-enabled task pane". 我正在构建一个VSTO加载项,需要“从Excel单元格拖放到启用拖动的任务窗格”。

So far I notice that I can only drag and drop within the cells themselves. 到目前为止,我注意到我只能在细胞内拖放。 It does not allow me to drop into the task Pane or drag past the sheet limits. 它不允许我放入任务窗格或拖过图纸限制。 (http://www.computerimages.com/tip_xl.html) (http://www.computerimages.com/tip_xl.html)

Note: The task pane has drag drop enabled, I ahve already tested I can drag/drop from task pane to excel but I need to do this the other way around? 注意:任务窗格已启用拖拽,我已经测试过我可以从任务窗格拖放到excel但是我需要反过来这样做吗?

From the IDE, set AllowDrop on the control you want to drop your data on, then wire up the events for DragOver and DragDrop on that same control. 在IDE中,在要删除数据的控件上设置AllowDrop ,然后在同一控件上连接DragOverDragDrop的事件。

Your code would look something like this: 您的代码看起来像这样:

TextBox TaskPane;

void DragNDrop(object sender, DragEventArgs e) {
  if (e.Effect == DragDropEffects.Move) {
    if (e.Data.GetDataPresent(DataFormats.CommaSeparatedValue)) {
      string csvText = e.Data.GetData(DataFormats.CommaSeparatedValue, false).ToString();
      if (!String.IsNullOrEmpty(csvText)) {
        TaskPane.Text = csvText;
      }
    }
  }
}

void DragOver(object sender, DragEventArgs e) {
  if (!e.Data.GetDataPresent(DataFormats.CommaSeparatedValue)) {
    e.Effect = DragDropEffects.None;
  } else {
    e.Effect = DragDropEffects.Move;
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM