简体   繁体   中英

C# How can I send a text with the data OnDragDrop

I am using a ListView control to hold items that are dropped on another form. I have everything working, except that I also need to include the .Name property of the SelectedIndex, and be able to keep the .Name and .Tag separate in the receiving method.

Where I start the drag:

listViewCurves.DoDragDrop(listViewCurves.SelectedItems[0].Tag, DragDropEffects.Copy);

Where I catch the drop:

Curve curve = (Curve)e.Data.GetData(typeof(Curve));

You can pass any object you want, so this might be a good time to use a Tuple<string, Curve> :

var selectedItem = listViewCurves.SelectedItems[0];

var data = Tuple.Create(selectedItem.Name, (Curve)selectedItem.Tag);

listViewCurves.DoDragDrop(data, DragDropEffects.Copy);

Retrieving end:

var data = (Tuple<string, Curve>)e.Data.GetData(typeof(Tuple<string, Curve>));

var name = data.Item1;
var curve = data.Item2;

You can read more about the Tuple class here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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