|
-
Dec 15th, 2011, 11:32 AM
#1
Thread Starter
New Member
Help with listview items
I am creating a program that allowes me to select items from a listview and save them in a .txt file.
Code:
Imports System.IO
Public Class cv7import
Private Sub cv7import_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim caminho As String
caminho = "C:\Documents and Settings\Software\Ambiente de trabalho\cv7import"
Dim returnValue As String()
returnValue = Environment.GetCommandLineArgs()
If returnValue.Length > 1 Then
MessageBox.Show(returnValue(1).ToString())
Else
MessageBox.Show("Nothing")
End If
' Set ListView Properties
lstvicon.View = View.Details
lstvicon.GridLines = False
lstvicon.FullRowSelect = True
lstvicon.HideSelection = False
lstvicon.MultiSelect = True
' Create Columns Headers
lstvicon.Columns.Add("Nome")
lstvicon.Columns.Add("Extensão")
lstvicon.Columns.Add("Tamanho")
lstvicon.Columns.Add("Data Modificação")
Dim DI As System.IO.DirectoryInfo = New System.IO.DirectoryInfo(caminho)
Dim files() As System.IO.FileInfo = DI.GetFiles
Dim file As System.IO.FileInfo
Dim li As ListViewItem
For Each file In files
li = lstvicon.Items.Add(file.Name)
li.SubItems.Add(file.Extension)
li.SubItems.Add(file.Length)
li.SubItems.Add(file.LastWriteTimeUtc)
'li.SubItems.Add(FileDialog)
Next
End Sub
Private Sub btnimp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnimp.Click
' Creates a csv File
Dim csv As New System.IO.StreamWriter("C:\Documents and Settings\Software\Ambiente de trabalho\cv7import\teste.csv", True)
lstvicon.SelectedItems.CopyTo(csv)
csv.Close()
End Sub
End Class
Can someone give me a push with this please?
-
Dec 15th, 2011, 12:30 PM
#2
Re: Help with listview items
try this:
vb Code:
Private Sub btnimp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnimp.Click
Dim items() As ListViewItem = lstvicon.SelectedItems.Cast(Of ListViewItem).ToArray
Dim csv() As String = Array.ConvertAll(items, Function(lvi) String.Join(",", lvi.SubItems.Cast(Of ListViewItem.ListViewSubItem).Select(Function(si) si.Text).ToArray))
IO.File.WriteAllLines("C:\Documents and Settings\Software\Ambiente de trabalho\cv7import\teste.csv", csv)
End Sub
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Dec 15th, 2011, 12:37 PM
#3
Thread Starter
New Member
Re: Help with listview items
damn that works perfectly!! thanks a lot.
Can you also help me on making the names be converted into short name? The format i really wanted was around this :
movieprograms : moviep~1
This being on the csv. Do you have any idea if this is possible?
-
Dec 15th, 2011, 12:44 PM
#4
Re: Help with listview items
here's an api function that gives you a short path from a file path:
vb Code:
Public Class Form1
Declare Function GetShortPathName Lib "kernel32" _
Alias "GetShortPathNameA" (ByVal lpszLongPath As String, _
ByVal lpszShortPath As String, ByVal cchBuffer As Integer) As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim shortPath As New String(" "c, 256)
GetShortPathName("long path here", shortPath, 256)
MsgBox(shortPath.Trim)
End Sub
End Class
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|