c++/clr 控件如何响应DragDrop事件

我是菜鸟999 2017-04-17 02:44:19
Form窗体的AllowDrop属性true
dotnetbar.panelex的AllowDrop属性true
dotnetbar.listviewex的AllowDrop属性true

想实现拖拽任何文件到listviewex上都能得到路径
但是,实际使用时没有任何反应。以下参考了微软的例子。

private: System::Void listViewEx_Strategys_DragOver(System::Object^ sender, System::Windows::Forms::DragEventArgs^ e) {
if ( !e->Data->GetDataPresent( System::String::typeid ) )
{
e->Effect = DragDropEffects::None;
this->labelItem_InfoTips->Text = "None - no string data.";
return;
}

// Set the effect based upon the KeyState.
if ( (e->KeyState & (8 + 32)) == (8 + 32) && ((e->AllowedEffect & DragDropEffects::Link) == DragDropEffects::Link) )
{
// KeyState 8 + 32 = CTL + ALT
// Link drag-and-drop effect.
e->Effect = DragDropEffects::Link;
}
else
if ( (e->KeyState & 32) == 32 && ((e->AllowedEffect & DragDropEffects::Link) == DragDropEffects::Link) )
{
// ALT KeyState for link.
e->Effect = DragDropEffects::Link;
}
else
if ( (e->KeyState & 4) == 4 && ((e->AllowedEffect & DragDropEffects::Move) == DragDropEffects::Move) )
{
// SHIFT KeyState for move.
e->Effect = DragDropEffects::Move;
}
else
if ( (e->KeyState & 8) == 8 && ((e->AllowedEffect & DragDropEffects::Copy) == DragDropEffects::Copy) )
{
// CTL KeyState for copy.
e->Effect = DragDropEffects::Copy;
}
else
if ( (e->AllowedEffect & DragDropEffects::Move) == DragDropEffects::Move )
{
// By default, the drop action should be move, if allowed.
e->Effect = DragDropEffects::Move;
}
else
e->Effect = DragDropEffects::None;


}


添加KeyUp函数却可以响应。

private: System::Void listViewEx_Strategys_KeyUp(System::Object^ sender, System::Windows::Forms::KeyEventArgs^ e) {
if (e->KeyCode == Keys::Delete)
{
this->listViewEx_Strategys->Items->Remove(this->listViewEx_Strategys->FocusedItem);
}
}


请问,怎么才能让DragDrop工作?
...全文
1301 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
我是菜鸟999 2017-04-24
  • 打赏
  • 举报
回复
唉!这个东西是不是太冷门了,都没人来啊
我是菜鸟999 2017-04-17
  • 打赏
  • 举报
回复
DevComponents::DotNetBar::Controls::ListViewEx的AllowDrop属性如果是true,则添加数据失败,不知道什么原因。

1,979

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 其他语言讨论
社区管理员
  • 其他语言社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧