Bonjour a tous,
je cherche a faire un drag&drop treeview vers une listbox...
J'ai essayé plusieurs fois avec ce que j'ai trouvé sur le net mais sans succes(le drop marche pas )
qqun l'aurait il deja fait?
merci
Bonjour a tous,
je cherche a faire un drag&drop treeview vers une listbox...
J'ai essayé plusieurs fois avec ce que j'ai trouvé sur le net mais sans succes(le drop marche pas )
qqun l'aurait il deja fait?
merci
as-tu positionné le allowdrop de ton control destination à true?
Quel est le code de tes fonctions DragEnter, DragOver et DragDrop de ton control destination?
Oui j'ai positionné les flags allowDrop a true
Je n'ai pas de drag over... est ce necessaire?
Voici le code source:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 private void Form1_Load(object sender, EventArgs e) { this.treeView1.ItemDrag += new System.Windows.Forms.ItemDragEventHandler(this.treeView_ItemDrag); this.treeView1.DragEnter += new System.Windows.Forms.DragEventHandler(this.my_DragEnter); this.listBox1.DragEnter += new System.Windows.Forms.DragEventHandler(this.my_DragEnter); this.listBox1.DragDrop += new System.Windows.Forms.DragEventHandler(this.listBox_DragDrop); } private void treeView_ItemDrag(object sender, System.Windows.Forms.ItemDragEventArgs e) { DoDragDrop(e.Item, DragDropEffects.Move); } private void my_DragEnter(object sender, System.Windows.Forms.DragEventArgs e) { e.Effect = DragDropEffects.Move; } private void listBox_DragDrop(object sender, System.Windows.Forms.DragEventArgs e) { listBox1.Items.Add(e.Data.GetData(DataFormats.Text)); }
Salut,
c'est le callback de TextBoxDragDrop qui coince. Tu dois typer l'objet du IDataObject pour le recuperer, ici en entrée tu lui donne un TreeNode (DoDragDrop(e.Item, DragDropEffects.Move)) et en sortie tu veux un text, ca ne marche pas. =)
Essaie plutot :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5 private void listBox_DragDrop(object sender, System.Windows.Forms.DragEventArgs e) { listBox1.Items.Add(e.Data.GetData(typeof(TreeNode))); }
Puisque ca n'a pas été fait, je te dis MERCI !!!
Vous avez un bloqueur de publicités installé.
Le Club Developpez.com n'affiche que des publicités IT, discrètes et non intrusives.
Afin que nous puissions continuer à vous fournir gratuitement du contenu de qualité, merci de nous soutenir en désactivant votre bloqueur de publicités sur Developpez.com.
Partager