HELP!Problem con Drag Drop en control personalizao
Publicado por Andriuuuuu (2 intervenciones) el 29/03/2007 09:24:59
Buenas a todos
He desarrollado un control que contiene un listbox y un boton. Esta programado para actuar cuando salta el evento dragdrop sobre el listbox. Si arrastro un archivo al listobox salta el evento.
el tema es que al insertar la dll en mi proyecto (VS2005 en una aplicacion de windows) selecciono mi control, lo pinta bien pero al ejecutarlo, intento arrastrar un archivo y no me deja.
Tiene la propiedad allowdrop=true tanto en el control como en la listbox que contiene.
He probado a crearme un listbox aparte en otro form y copiando y pegando el codigo de mi control me permite hacer dragdrop sin problemas.
Sabéis porque puede ser?
Muchas gracias de antemano! Me estoy volviendo locoooooooooooooo
Os pongo el code de la clase del control y la clase designervb para ver si veis algo raro...
Imports Microsoft.Office.Interop
Public Class ListBoxDragAndDrop
Private _rutaservidor As String
Property rutaservidor() As String
Get
Return _rutaservidor
End Get
Set(ByVal value As String)
_rutaservidor = value
End Set
End Property
Private Sub ListDragDrop_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs)
Dim nuevoguid As Guid
Dim filestr As IO.FileStream
'Dim archivo As IO.File
Try
If (e.Data.GetDataPresent("FileName", False) And e.Data.GetDataPresent("filedrop", False)) Then
Dim fs As IO.FileStream = Nothing
Dim ms As IO.MemoryStream = Nothing
Dim rutaarchiv As String = ""
Dim nombrearchi As String = ""
Dim arraypath() As String
Try
nombrearchi = CType(e.Data.GetData(DataFormats.FileDrop), Array).GetValue(0).ToString
ListDragDrop.Items.Add(nombrearchi)
arraypath = nombrearchi.Split("\")
filestr = New IO.FileStream(nombrearchi, IO.FileMode.Open, IO.FileAccess.Read)
Dim b() As Byte = New Byte(Convert.ToInt32(filestr.Length)) {}
If IO.File.Exists(nombrearchi) = True Then
'IO.File.Create(_rutaservidor & arraypath(arraypath.Length - 1), b.Length)
If IO.File.Exists(_rutaservidor & arraypath(arraypath.Length - 1)) = False Then
IO.File.Copy(nombrearchi, _rutaservidor & arraypath(arraypath.Length - 1), b.Length)
'ListDragDrop.Items.Add("ARCHIVO: " & _rutaservidor & arraypath(arraypath.Length - 1).ToString)
ListDragDrop.Items.Add("ARCHIVO: " & nombrearchi)
MessageBox.Show("Archivo subido al servidor", "Archivo subido", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
MessageBox.Show("El archivo ya existe en el servidor", "Archivo ya existe", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End If
If Not filestr Is Nothing Then
filestr.Close()
filestr.Dispose()
filestr = Nothing
End If
Catch ex As Exception
Finally
If Not fs Is Nothing Then
fs.Close()
fs.Dispose()
fs = Nothing
End If
End Try
Else
'Esto es que no esta abierto el outlook o que esta haciendo drag desde otro sitio
Dim OL As Microsoft.Office.Interop.Outlook.Application = GetObject(, "Outlook.Application")
Dim mi As Microsoft.Office.Interop.Outlook.MailItem
Dim conta = 0
Dim rutas As String = ""
If OL.ActiveExplorer.Selection.Count = 0 Then
'Esta abierto pero no hay seleccion de outlook
Else
For Each mi In OL.ActiveExplorer.Selection()
nuevoguid = Guid.NewGuid()
If IO.File.Exists(_rutaservidor & mi.Subject.ToString.Trim.Replace(" ", "_") & nuevoguid.ToString & ".msg") = False Then
mi.SaveAs(_rutaservidor & mi.Subject.ToString.Trim.Replace(" ", "_") & nuevoguid.ToString & ".msg")
ListDragDrop.Items.Add("E-MAIL: " & _rutaservidor & mi.Subject.ToString.Trim.Replace(" ", "_") & nuevoguid.ToString & ".msg")
Else
MessageBox.Show("El Email ya existe en el servidor", "E-Mail ya existe", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
Next
MessageBox.Show("Email/s subido al servidor", "Archivo subido", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
If Not mi Is Nothing Then
mi.Close(Outlook.OlInspectorClose.olDiscard)
mi = Nothing
End If
End If
Catch ex As Exception
End Try
End Sub
Private Sub ListDragDrop_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs)
Try
e.Effect = DragDropEffects.Copy
Catch ex As Exception
End Try
End Sub
Private Sub btborrar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btborrar.Click
Dim selec As ListBox.SelectedObjectCollection
'Dim selecindexes As ListBox.SelectedIndexCollection
Dim arraypath() As String
Dim arrayborr As New ArrayList
Try
If ListDragDrop.SelectedItems.Count > 0 Then
selec = ListDragDrop.SelectedItems
'selecindexes = ListBox1.SelectedIndices
For i As Integer = 0 To selec.Count - 1
arraypath = Nothing
arraypath = selec(i).ToString.Split("\")
If IO.File.Exists(_rutaservidor & arraypath(arraypath.Length - 1)) Then
IO.File.Delete(_rutaservidor & arraypath(arraypath.Length - 1))
arrayborr.Add(selec(i).ToString)
MessageBox.Show("Archivo " & _rutaservidor & arraypath(arraypath.Length - 1) & "borrado del servidor")
Else
MessageBox.Show("El archivo " & _rutaservidor & arraypath(arraypath.Length - 1) & "no se encuentra en el servidor")
End If
Next
For j As Integer = 0 To arrayborr.Count - 1
ListDragDrop.Items.Remove(arrayborr(j).ToString)
Next
Else
MessageBox.Show("Tienes que seleccionar por lo menos un archivo")
End If
If Not arrayborr Is Nothing Then
arrayborr.Clear()
arrayborr = Nothing
End If
Catch ex As Exception
End Try
End Sub
End Class
No me cabe la del designer en este men os lo pongo en otro
He desarrollado un control que contiene un listbox y un boton. Esta programado para actuar cuando salta el evento dragdrop sobre el listbox. Si arrastro un archivo al listobox salta el evento.
el tema es que al insertar la dll en mi proyecto (VS2005 en una aplicacion de windows) selecciono mi control, lo pinta bien pero al ejecutarlo, intento arrastrar un archivo y no me deja.
Tiene la propiedad allowdrop=true tanto en el control como en la listbox que contiene.
He probado a crearme un listbox aparte en otro form y copiando y pegando el codigo de mi control me permite hacer dragdrop sin problemas.
Sabéis porque puede ser?
Muchas gracias de antemano! Me estoy volviendo locoooooooooooooo
Os pongo el code de la clase del control y la clase designervb para ver si veis algo raro...
Imports Microsoft.Office.Interop
Public Class ListBoxDragAndDrop
Private _rutaservidor As String
Property rutaservidor() As String
Get
Return _rutaservidor
End Get
Set(ByVal value As String)
_rutaservidor = value
End Set
End Property
Private Sub ListDragDrop_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs)
Dim nuevoguid As Guid
Dim filestr As IO.FileStream
'Dim archivo As IO.File
Try
If (e.Data.GetDataPresent("FileName", False) And e.Data.GetDataPresent("filedrop", False)) Then
Dim fs As IO.FileStream = Nothing
Dim ms As IO.MemoryStream = Nothing
Dim rutaarchiv As String = ""
Dim nombrearchi As String = ""
Dim arraypath() As String
Try
nombrearchi = CType(e.Data.GetData(DataFormats.FileDrop), Array).GetValue(0).ToString
ListDragDrop.Items.Add(nombrearchi)
arraypath = nombrearchi.Split("\")
filestr = New IO.FileStream(nombrearchi, IO.FileMode.Open, IO.FileAccess.Read)
Dim b() As Byte = New Byte(Convert.ToInt32(filestr.Length)) {}
If IO.File.Exists(nombrearchi) = True Then
'IO.File.Create(_rutaservidor & arraypath(arraypath.Length - 1), b.Length)
If IO.File.Exists(_rutaservidor & arraypath(arraypath.Length - 1)) = False Then
IO.File.Copy(nombrearchi, _rutaservidor & arraypath(arraypath.Length - 1), b.Length)
'ListDragDrop.Items.Add("ARCHIVO: " & _rutaservidor & arraypath(arraypath.Length - 1).ToString)
ListDragDrop.Items.Add("ARCHIVO: " & nombrearchi)
MessageBox.Show("Archivo subido al servidor", "Archivo subido", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
MessageBox.Show("El archivo ya existe en el servidor", "Archivo ya existe", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End If
If Not filestr Is Nothing Then
filestr.Close()
filestr.Dispose()
filestr = Nothing
End If
Catch ex As Exception
Finally
If Not fs Is Nothing Then
fs.Close()
fs.Dispose()
fs = Nothing
End If
End Try
Else
'Esto es que no esta abierto el outlook o que esta haciendo drag desde otro sitio
Dim OL As Microsoft.Office.Interop.Outlook.Application = GetObject(, "Outlook.Application")
Dim mi As Microsoft.Office.Interop.Outlook.MailItem
Dim conta = 0
Dim rutas As String = ""
If OL.ActiveExplorer.Selection.Count = 0 Then
'Esta abierto pero no hay seleccion de outlook
Else
For Each mi In OL.ActiveExplorer.Selection()
nuevoguid = Guid.NewGuid()
If IO.File.Exists(_rutaservidor & mi.Subject.ToString.Trim.Replace(" ", "_") & nuevoguid.ToString & ".msg") = False Then
mi.SaveAs(_rutaservidor & mi.Subject.ToString.Trim.Replace(" ", "_") & nuevoguid.ToString & ".msg")
ListDragDrop.Items.Add("E-MAIL: " & _rutaservidor & mi.Subject.ToString.Trim.Replace(" ", "_") & nuevoguid.ToString & ".msg")
Else
MessageBox.Show("El Email ya existe en el servidor", "E-Mail ya existe", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
Next
MessageBox.Show("Email/s subido al servidor", "Archivo subido", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
If Not mi Is Nothing Then
mi.Close(Outlook.OlInspectorClose.olDiscard)
mi = Nothing
End If
End If
Catch ex As Exception
End Try
End Sub
Private Sub ListDragDrop_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs)
Try
e.Effect = DragDropEffects.Copy
Catch ex As Exception
End Try
End Sub
Private Sub btborrar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btborrar.Click
Dim selec As ListBox.SelectedObjectCollection
'Dim selecindexes As ListBox.SelectedIndexCollection
Dim arraypath() As String
Dim arrayborr As New ArrayList
Try
If ListDragDrop.SelectedItems.Count > 0 Then
selec = ListDragDrop.SelectedItems
'selecindexes = ListBox1.SelectedIndices
For i As Integer = 0 To selec.Count - 1
arraypath = Nothing
arraypath = selec(i).ToString.Split("\")
If IO.File.Exists(_rutaservidor & arraypath(arraypath.Length - 1)) Then
IO.File.Delete(_rutaservidor & arraypath(arraypath.Length - 1))
arrayborr.Add(selec(i).ToString)
MessageBox.Show("Archivo " & _rutaservidor & arraypath(arraypath.Length - 1) & "borrado del servidor")
Else
MessageBox.Show("El archivo " & _rutaservidor & arraypath(arraypath.Length - 1) & "no se encuentra en el servidor")
End If
Next
For j As Integer = 0 To arrayborr.Count - 1
ListDragDrop.Items.Remove(arrayborr(j).ToString)
Next
Else
MessageBox.Show("Tienes que seleccionar por lo menos un archivo")
End If
If Not arrayborr Is Nothing Then
arrayborr.Clear()
arrayborr = Nothing
End If
Catch ex As Exception
End Try
End Sub
End Class
No me cabe la del designer en este men os lo pongo en otro
Valora esta pregunta


0