Glisser deplacer d'une listbox vers textbox

hy_honey Messages postés 67 Date d'inscription lundi 9 mai 2005 Statut Membre Dernière intervention 8 août 2005 - 28 juil. 2005 à 10:32
cs_drahcir Messages postés 745 Date d'inscription mardi 30 novembre 2004 Statut Membre Dernière intervention 15 septembre 2009 - 28 juil. 2005 à 17:38
bonjour a tous
je suis en vb.net et je bloc depuid quelque jour , j'ai essayer de codé un drap and drop d'une liste box vers un text box c'est a dire quand je veux récuperer l'un des nom de mes client générer dans une liste box et l'afficher dans un textbox mais j'ai une erreur dans mon code.
quand je récupère un nom d'un de mes client d'une listbox vers une textbox . dans le text box cela m'affiche system.data.datarowview et je ne vois pas d'ou vient l'erreure voici mon code si si quelqu'un peu m'aider
' recuperer de la liste box le nom d'un client


Private
Sub ListBox1_MouseDown(
ByVal sender
As
Object,
ByVal e
As System.Windows.Forms.MouseEventArgs)
Handles ListBox1.MouseDown


ListBox1.DoDragDrop(ListBox1.SelectedItems(ListBox1.IndexFromPoint(e.X, e.Y).ToString).GetType.ToString, DragDropEffects.Copy
Or DragDropEffects.Move)



End
Sub

'afficher dans mon text box



Private
Sub l9_DragEnter(
ByVal sender
As
Object,
ByVal e
As System.Windows.Forms.DragEventArgs)
Handles L9.DragEnter



If (e.Data.GetDataPresent(
GetType(System.String)))
Then


e.Effect = DragDropEffects.Copy



Else


e.Effect = DragDropEffects.None



End
If



End
Sub



Private
Sub l9_DragDrop(
ByVal sender
As
Object,
ByVal e
As System.Windows.Forms.DragEventArgs)
Handles L9.DragDrop


L9.Text = e.Data.GetData(DataFormats.Text).ToString



End
Sub

26 réponses

cs_drahcir Messages postés 745 Date d'inscription mardi 30 novembre 2004 Statut Membre Dernière intervention 15 septembre 2009 4
28 juil. 2005 à 16:44
Je viens de tester ton code, j'ai trouvé ce qui ne vas pas, voici le code qui fonctionne :


Private
Sub ListBox1_MouseDown(
ByVal sender
As
Object,
ByVal e
As System.Windows.Forms.MouseEventArgs)
Handles ListBox1.MouseDown


ListBox1.DoDragDrop(ListBox1.Items(ListBox1.IndexFromPoint(e.X, e.Y)), DragDropEffects.Copy
Or DragDropEffects.Move)



End
Sub
Tu ajoutes .GetType.ToString après avoir récupérer le texte de ta listBox, et ceci te renvoie le type, non pas le contenu.

@+
0
hy_honey Messages postés 67 Date d'inscription lundi 9 mai 2005 Statut Membre Dernière intervention 8 août 2005
28 juil. 2005 à 16:57
non sela ne marche toujours pas désolé voila je te récrie le code que je vien a l'instant de tester avec les modif que tu m'a remis:

'primière procedure du click de la souris

Private
Sub ListBox1_MouseDown(
ByVal sender
As
Object,
ByVal e
As System.Windows.Forms.MouseEventArgs)
Handles ListBox1.MouseDown


ListBox1.DoDragDrop(ListBox1.Items(ListBox1.IndexFromPoint(e.X, e.Y)), DragDropEffects.Copy
Or DragDropEffects.Move)



End
Sub


'deusieme procedure



Private
Sub l9_DragEnter(
ByVal sender
As
Object,
ByVal e
As System.Windows.Forms.DragEventArgs)
Handles L9.DragEnter



If (e.Data.GetDataPresent(
GetType(System.String)))
Then


e.Effect = DragDropEffects.Copy



Else


e.Effect = DragDropEffects.None



End
If



End
Sub



'3eme procedure de l'affichage

Private
Sub l9_DragDrop(
ByVal sender
As
Object,
ByVal e
As System.Windows.Forms.DragEventArgs)
Handles L9.DragDrop


L9.Text = e.Data.GetData(DataFormats.Text).ToString



End
Sub

l'erreur est qu'il ne me donne pas l'autorisation de déclicker pour vider dans le text box
c'est a dire quand je click et je reste clicker il y a un interdi qui suit le curseur et normalement il doit disparettre quand jarrive au textbox mais il ne disparait pas que faire

aide moi stp je suis sur qu'on est prés du but
0
cs_drahcir Messages postés 745 Date d'inscription mardi 30 novembre 2004 Statut Membre Dernière intervention 15 septembre 2009 4
28 juil. 2005 à 17:20
J'ai exactement le même code que toi, et moi ça marche!!! La propriété AllowDrop de ton TextBox est-elle à True?
0
hy_honey Messages postés 67 Date d'inscription lundi 9 mai 2005 Statut Membre Dernière intervention 8 août 2005
28 juil. 2005 à 17:33
oui il é bien a true

tu é en vb6.net????

je comprend plus rien!!!!!!!
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
hy_honey Messages postés 67 Date d'inscription lundi 9 mai 2005 Statut Membre Dernière intervention 8 août 2005
28 juil. 2005 à 17:36
il y a quelque chose qui cloche a mon avis c pas possible
0
cs_drahcir Messages postés 745 Date d'inscription mardi 30 novembre 2004 Statut Membre Dernière intervention 15 septembre 2009 4
28 juil. 2005 à 17:38
je suis bien en vb.net. Je te post le code que j'ai crée :

Private
Sub ListBox1_MouseDown(
ByVal sender
As
Object,
ByVal e
As System.Windows.Forms.MouseEventArgs)
Handles ListBox1.MouseDown


ListBox1.DoDragDrop(ListBox1.Items(ListBox1.IndexFromPoint(e.X, e.Y)), DragDropEffects.Copy
Or DragDropEffects.Move)



End
Sub



Private
Sub TextBox1_DragEnter(
ByVal sender
As
Object,
ByVal e
As System.Windows.Forms.DragEventArgs)
Handles TextBox1.DragEnter



If (e.Data.GetDataPresent(
GetType(System.String)))
Then


e.Effect = DragDropEffects.Copy



Else


e.Effect = DragDropEffects.None



End
If



End
Sub



Private
Sub TextBox1_DragDrop(
ByVal sender
As
Object,
ByVal e
As System.Windows.Forms.DragEventArgs)
Handles TextBox1.DragDrop


TextBox1.Text = e.Data.GetData(DataFormats.Text).ToString



End
Sub
0
Rejoignez-nous