vb@rchiv
VB Classic
VB.NET
ADO.NET
VBA
C#
Zippen wie die Profis!  
 vb@rchiv Quick-Search: Suche startenErweiterte Suche starten   Impressum  | Datenschutz  | vb@rchiv CD Vol.6  | Shop Copyright ©2000-2024
 
zurück

 Sie sind aktuell nicht angemeldet.Funktionen: Einloggen  |  Neu registrieren  |  Suchen

VB.NET - Ein- und Umsteiger
MouseMove bei Listbox 
Autor: stefanbla80
Datum: 28.08.08 16:46

Hallo!!

Ich habe eine Listbox mit verschiedenen Dateien als Inhalt. Z. B. Test.xls
Ich würde mir gerne den Pfad der Datei (z.B. c:\test\Test.xls) mit anzeigen lassen wenn ich über die Datei mit MouseMove drüber gehe.

Wie geht denn das?!


 Private Sub ListBox1_MouseMove(ByVal sender As Object, ByVal e As _
   System.Windows.Forms.MouseEventArgs) Handles _
    ListBox1.MouseMove, ListBox2.MouseMove, _
    ListBox3.MouseMove, ListBox4.MouseMove, _
    ListBox5.MouseMove, ListBox6.MouseMove
 
    End Sub
Themenbaum einblendenGesamtübersicht  |  Zum Thema  |  Suchen

Re: MouseMove bei Listbox 
Autor: stefanbla80
Datum: 28.08.08 16:52

Anbei noch der komplette Code.

Public Class Form5
    Dim x$, y$, pathxx$, folder$
 
 
    'Suche nach Angebots-Ordner und öffnen
    '##########################################################################
    ' #########################
    Private Const laufwerk2 = "Z:\INT\Data\CustomerSolutions\Systems\DE_SY\"
 
    Private Sub TextBox57_TextChanged(ByVal sender As System.Object, ByVal e As _
      System.EventArgs) Handles TextBox57.TextChanged
 
        x = TextBox57.Text
        y = TextBox58.Text
        If Microsoft.VisualBasic.Len(x) = 6 Then
 
            folder = Microsoft.VisualBasic.Left(x, 4) + "xx"
            pathxx = laufwerk2 + folder + "\" + x + "\" + y ' + ordner2
            GetFiles(pathxx)
            TextBox1.Text = pathxx
 
        End If
    End Sub
 
 
    Dim xlslist, pdflist, restlist, xlsmlist, doclist, msglist As New List(Of _
      String)
 
    Private Sub GetFiles(ByVal path As String)
        If IO.Directory.Exists(path) Then
            Dim glist As New List(Of String)
            pdflist.Clear() : ListBox1.Items.Clear()
            xlslist.Clear() : ListBox2.Items.Clear()
            xlsmlist.Clear() : ListBox3.Items.Clear()
            doclist.Clear() : ListBox4.Items.Clear()
            msglist.Clear() : ListBox5.Items.Clear()
            restlist.Clear() : ListBox6.Items.Clear()
            glist.AddRange(IO.Directory.GetFiles(path, "*.*", _
              IO.SearchOption.AllDirectories))
            For Each s As String In glist
                Select Case IO.Path.GetExtension(s)
                    Case ".pdf" : pdflist.Add(s) : ListBox1.Items.Add( _
                      IO.Path.GetFileName(s))
                    Case ".xls" : xlslist.Add(s) : ListBox2.Items.Add( _
                    IO.Path.GetFileName(s))
                    Case ".xlsm" : xlsmlist.Add(s) : ListBox3.Items.Add( _
                    IO.Path.GetFileName(s))
                    Case ".doc" : doclist.Add(s) : ListBox4.Items.Add( _
                    IO.Path.GetFileName(s))
                    Case ".msg" : msglist.Add(s) : ListBox5.Items.Add( _
                    IO.Path.GetFileName(s))
                    Case Else : restlist.Add(s) : ListBox6.Items.Add( _
                    IO.Path.GetFileName(s))
                End Select
            Next
        End If
    End Sub
 
    Private Sub ListBox_MouseDoubleClick(ByVal sender As Object, ByVal e As _
      System.Windows.Forms.MouseEventArgs) Handles _
    ListBox1.MouseDoubleClick, ListBox2.MouseDoubleClick, _
    ListBox3.MouseDoubleClick, ListBox4.MouseDoubleClick, _
    ListBox5.MouseDoubleClick, ListBox6.MouseDoubleClick
        Dim lb As ListBox = CType(sender, ListBox)
        If lb.IndexFromPoint(e.X, e.Y) > -1 Then
            Select Case lb.Name
                Case "ListBox1" : Process.Start(pdflist(lb.IndexFromPoint(e.X, _
                  e.Y)))
                Case "ListBox2" : Process.Start(xlslist(lb.IndexFromPoint(e.X, _
                e.Y)))
                Case "ListBox3" : Process.Start(xlsmlist(lb.IndexFromPoint(e.X, _
                e.Y)))
                Case "ListBox4" : Process.Start(doclist(lb.IndexFromPoint(e.X, _
                e.Y)))
                Case "ListBox5" : Process.Start(msglist(lb.IndexFromPoint(e.X, _
                e.Y)))
                Case "ListBox6" : Process.Start(restlist(lb.IndexFromPoint(e.X, _
                e.Y)))
            End Select
        End If
    End Sub
 
 
    Private Sub Button2_Click_1(ByVal sender As System.Object, ByVal e As _
      System.EventArgs) Handles Button2.Click
        Me.Close()
    End Sub
 
    Private Sub ListBox1_MouseMove(ByVal sender As Object, ByVal e As _
      System.Windows.Forms.MouseEventArgs) Handles _
    ListBox1.MouseMove, ListBox2.MouseMove, _
    ListBox3.MouseMove, ListBox4.MouseMove, _
    ListBox5.MouseMove, ListBox6.MouseMove
 
    End Sub
End Class
Themenbaum einblendenGesamtübersicht  |  Zum Thema  |  Suchen

Re: MouseMove bei Listbox 
Autor: GPM
Datum: 28.08.08 17:53

Mal ein anderer Ansatz ohne Listen.
Eventuell kommst du damit besser klar.
Der Pfad wird bei MouseMove in Label1 angezeigt:
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As _
      System.EventArgs) Handles Button1.Click
        ListBox1.Items.Clear() : ListBox2.Items.Clear() : ListBox3.Items.Clear()
        ListBox4.Items.Clear() : ListBox5.Items.Clear() : ListBox6.Items.Clear()
        GetFiles(TextBox1.Text)
    End Sub
 
    Private Sub GetFiles(ByVal path As String)
        If IO.Directory.Exists(path) Then
            For Each pfad As String In IO.Directory.GetFiles(path, "*.*", _
              IO.SearchOption.AllDirectories)
                Dim di As New DataItem(IO.Path.GetFileName(pfad), pfad)
                Select Case IO.Path.GetExtension(pfad)
                    Case ".pdf" : ListBox1.Items.Add(di)
                    Case ".xls" : ListBox2.Items.Add(di)
                    Case ".xlsm" : ListBox3.Items.Add(di)
                    Case ".doc" : ListBox4.Items.Add(di)
                    Case ".msg" : ListBox5.Items.Add(di)
                    Case Else : ListBox6.Items.Add(di)
                End Select
            Next
        End If
    End Sub
 
    Private Sub ListBox_MouseDoubleClick(ByVal sender As Object, ByVal e As _
      System.Windows.Forms.MouseEventArgs) Handles _
    ListBox1.MouseDoubleClick, ListBox2.MouseDoubleClick, _
    ListBox3.MouseDoubleClick, _
    ListBox4.MouseDoubleClick, ListBox5.MouseDoubleClick, _
    ListBox6.MouseDoubleClick
        Dim lb As ListBox = CType(sender, ListBox)
        Dim item As Int32 = lb.IndexFromPoint(e.X, e.Y)
        If item > -1 Then Process.Start(CType(lb.Items(item), DataItem).Pfad)
    End Sub
 
    Private Sub ListBox1_MouseMove(ByVal sender As Object, ByVal e As _
      System.Windows.Forms.MouseEventArgs) Handles _
    ListBox1.MouseMove, ListBox2.MouseMove, ListBox3.MouseMove, _
    ListBox4.MouseMove, ListBox5.MouseMove, ListBox6.MouseMove
        Dim lb As ListBox = CType(sender, ListBox)
        Dim item As Int32 = lb.IndexFromPoint(e.X, e.Y)
        If item > -1 Then
            Label1.Text = CType(lb.Items(item), DataItem).Pfad
        Else
            Label1.Text = ""
        End If
    End Sub
End Class
 
Public Class DataItem
    Private _pfad As String
    Private _name As String
 
    Public Sub New(ByVal fname As String, ByVal pfad As String)
        _name = fname
        _pfad = pfad
    End Sub
 
    Public ReadOnly Property Pfad() As String
        Get
            Return _pfad
        End Get
    End Property
 
    Public Overrides Function ToString() As String
        Return _name
    End Function
End Class
MfG GPM
0
Themenbaum einblendenGesamtübersicht  |  Zum Thema  |  Suchen

Re: MouseMove bei Listbox 
Autor: stefanbla80
Datum: 29.08.08 08:31

Genial, bin schwer beeindruckt!!!
Super Teil!!

Ein Wunsch noch, dann bin ich für den Fall befriedigt....

Ist noch eine Anzeige möglich, wie im Explorer, wann die Datei erstellt oder gespeichert wurde?!
Themenbaum einblendenGesamtübersicht  |  Zum Thema  |  Suchen

Re: MouseMove bei Listbox 
Autor: Julian13
Datum: 31.08.08 22:41

Hallo,

ja da gibts ein paar infos in My.Computer.FileSystem.GetFileInfo("Dateiname") darin gibts dann informationen wie erstellungsdatum usw.

Gruß Julian13
Themenbaum einblendenGesamtübersicht  |  Zum Thema  |  Suchen

Re: MouseMove bei Listbox 
Autor: keco
Datum: 01.09.08 17:59

Ich würde aber eher die Klasse DataItem um entsprechende Eigenschaften erweitern, anstatt ein neues FileInfo-Object erstellen zu müssen.
Themenbaum einblendenGesamtübersicht  |  Zum Thema  |  Suchen

Re: MouseMove bei Listbox 
Autor: stefanbla80
Datum: 02.09.08 07:35

Hab ich mir auch gedacht, nur ich komme da immer auf Fehler.

Hast Du mir ein Beispiel.
Themenbaum einblendenGesamtübersicht  |  Zum Thema  |  Suchen

Re: MouseMove bei Listbox 
Autor: GPM
Datum: 02.09.08 10:40

Als Beispiel die Änderungen für die Erweitung um LastWriteTime:
Private Sub GetFiles(ByVal path As String)
        If IO.Directory.Exists(path) Then
            For Each pfad As String In IO.Directory.GetFiles(path, "*.*", _
              IO.SearchOption.AllDirectories)
                Dim fi As New IO.FileInfo(pfad)
                Dim di As New DataItem(fi.Name, pfad, fi.LastWriteTime)
                Select Case IO.Path.GetExtension(pfad)
                    Case ".pdf" : ListBox1.Items.Add(di)
                    Case ".xls" : ListBox2.Items.Add(di)
                    Case ".xlsm" : ListBox3.Items.Add(di)
                    Case ".doc" : ListBox4.Items.Add(di)
                    Case ".msg" : ListBox5.Items.Add(di)
                    Case Else : ListBox6.Items.Add(di)
                End Select
            Next
        End If
End Sub
Private Sub ListBox1_MouseMove(ByVal sender As Object, ByVal e As _
      System.Windows.Forms.MouseEventArgs) Handles _
    ListBox1.MouseMove, ListBox2.MouseMove, ListBox3.MouseMove, _
    ListBox4.MouseMove, ListBox5.MouseMove, ListBox6.MouseMove
        Dim lb As ListBox = CType(sender, ListBox)
        Dim item As Int32 = lb.IndexFromPoint(e.X, e.Y)
        If item > -1 Then
            Label1.Text = CType(lb.Items(item), DataItem).Pfad & vbNewLine & _
            "LastWritetime " & CType(lb.Items(item), DataItem).LastWritetime
        Else
            Label1.Text = ""
        End If
End Sub
Public Class DataItem
    Private _pfad As String
    Private _name As String
    Private _lastwritetime As String
 
    Public Sub New(ByVal fname As String, ByVal pfad As String, ByVal lwt As _
      String)
        _name = fname
        _pfad = pfad
        _lastwritetime = lwt
    End Sub
 
    Public ReadOnly Property Pfad() As String
        Get
            Return _pfad
        End Get
    End Property
 
    Public ReadOnly Property LastWritetime() As String
        Get
            Return _lastwritetime
        End Get
    End Property
 
    Public Overrides Function ToString() As String
        Return _name
    End Function
End Class
MfG GPM
0
Themenbaum einblendenGesamtübersicht  |  Zum Thema  |  Suchen

Re: MouseMove bei Listbox 
Autor: stefanbla80
Datum: 02.09.08 15:34

Hallo GPM!!

Colle Sache. Kann ich mir die LastWriteTime bzw. auch das Datum in der ListBox anzeigen lassen, also z. B. vor dem Dateiname. Oder noch besser. In einer Extra ListBox
Themenbaum einblendenGesamtübersicht  |  Zum Thema  |  Suchen

Sie sind nicht angemeldet!
Um auf diesen Beitrag zu antworten oder neue Beiträge schreiben zu können, müssen Sie sich zunächst anmelden.

Einloggen  |  Neu registrieren

Funktionen:  Zum Thema  |  GesamtübersichtSuchen 

nach obenzurück
 
   

Copyright ©2000-2024 vb@rchiv Dieter Otter
Alle Rechte vorbehalten.
Microsoft, Windows und Visual Basic sind entweder eingetragene Marken oder Marken der Microsoft Corporation in den USA und/oder anderen Ländern. Weitere auf dieser Homepage aufgeführten Produkt- und Firmennamen können geschützte Marken ihrer jeweiligen Inhaber sein.

Diese Seiten wurden optimiert für eine Bildschirmauflösung von mind. 1280x1024 Pixel