如何将从Excel单元格拖拽到启用拖放的任务窗格?

时间:2022-08-13 19:40:47

I am using 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".

我正在使用Excel 2007, VS2008 Pro。我正在构建一个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,但是我需要用另一种方式来做?

1 个解决方案

#1


1  

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,然后在相同的控件上为DragOver和DragDrop连接事件。

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;
  }
}

#1


1  

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,然后在相同的控件上为DragOver和DragDrop连接事件。

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;
  }
}