1

だから私はobjectlistview(実際にはtreelistview)を持っています。これからリッチテキストボックスにアイテムをドラッグして、ドラッグしたアイテムのプロパティを挿入できるようにしたい (この場合はDefault_Heirarchy_ID)

TreeListView の objectmodel は、List<T>というクラスのSpecItemです。

これは私がこれまでに持っているものです:

    public frmAutospecEditor(SpecItem siThis_, List<SpecItem> lstStock_)
    {
        InitializeComponent();

        txtFormula.DragEnter += new DragEventHandler(txtFormula_DragEnter);
        txtFormula.DragDrop += new DragEventHandler(txtFormula_DragDrop);
        ...
    }

    void txtFormula_DragEnter(object sender, DragEventArgs e)
    {
        e.Effect = DragDropEffects.Copy;
    }

    private void tlvSpecItem_ItemDrag(object sender, ItemDragEventArgs e)
    {
        int intID = ((SpecItem)tlvSpecItem.GetItem(tlvSpecItem.SelectedIndex).RowObject).Default_Heirarchy_ID ??0;
        DoDragDrop(intID, DragDropEffects.Copy);
    }
    private void txtFormula_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
    {

        object objID = e.Data.GetData(typeof(String)); 
        //this is where it goes wrong - no matter what I try to do with this, it 
        //always returns either null, or the text displayed for that item in the TreeListView,               
        //NOT the ID as I want it to.
        string strID = (string)objID;
        txtFormula.Text = strID;
    }

どこが間違っていますか?

乾杯

4

1 に答える 1

1

Drag は、(OLV) からデータを取得するコントロールです。Drop は宛先コントロール (テキスト ボックス) です。そう:

IsSimpleDragSourceOLVのプロパティを true に設定します。

テキスト ボックスでAllowDropプロパティを true に設定します。次にDragEnter、テキストボックスのイベントを処理し、DragEventArgsparam を使用します。

ModelDropped イベントを処理します。

private void yourOlv_ModelDropped(object sender, ModelDropEventArgs e) 
{ 
   // If they didn't drop on anything, then don't do anything 
   if (e.TargetModel == null) return; 

   // Use the dropped data: 
   // ((SpecItem)e.TargetModel) 
   // foreach (SpecItem si in e.SourceModels) ...

   // e.RefreshObjects(); 
}

詳細: http://objectlistview.sourceforge.net/cs/dragdrop.html#ixzz1lEt7LoGr

于 2012-02-02T15:39:16.320 に答える