2012-03-12 3 views
0
private void treeView_ItemDrag(object sender, ItemDragEventArgs e) 
{ 
    try 
    { 
     IVariable variable = getSelectedNode(); 
     this.treeView.DoDragDrop((Variable)variable, DragDropEffects.Copy); 
    } 
    catch (Exception)  {  } 
} 

private void splitContainer_Panel2_DragDrop(object sender, DragEventArgs e) 
{ 

    Variable var = (Variable)(e.Data); 
} 

변수는 가변 개체 (싱글 톤 패턴)입니다. 이 객체를 트리 뷰에서 다른 뷰로 드래그하여 객체를 그려 보겠습니다. 나는이 오류 코드를 얻을 :. 유형의 목적 "System.Windows.Forms.DataObject는" 'ORANGE_VARIABLE.Variable "를 입력 변환 할 수 없습니다C#으로 개체를 드래그하는 방법은 무엇입니까? (배치)

내가 내 권리 개체가 data.form. 내가이 객체를 풀다 수있는 방법

?

답변

2

당신이 DoDragDrop를 호출하여 Variable 객체는 자동으로 DataObject에 싸여있다. 마지막 ret하기 그것을 시도하면 검색 할 데이터의 유형이 GetData이어야합니다.

Variable var = (Variable)e.Data.GetData(typeof(Variable)); 
+0

감사합니다! 그 일 – Thomas

관련 문제