6 Replies - 1099 Views - Last Post: 16 September 2012 - 06:10 AM Rate Topic: -----

#1 WhaleTrain  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 15-September 12

Question/Problem: Trying to get listview to show files

Posted 15 September 2012 - 11:23 AM

Hello there guys just wondering if you could help me with a little problem I am having with my VB code. My aim is simple: To create an application that lists files from a selected directory into a table. So far I have been unable to achieve this mainly because I cannot get the ListView to show any files when a directory is selected. I have inputted a Folder BrowserDiaglog and have managed to get the buttons and the text box to show the directory when selected. I want the ListView to read what directory is selected in the text box and display all files in that folder on the listview. If possible, how can I modify my code to do so?

Public Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        List.Sorting = SortOrder.Ascending
        List.View = View.Details = TxtDir.Text

    End Sub

    Private Sub cmdQuit_Click(sender As Object, e As EventArgs) Handles cmdQuit.Click
        Me.Close()
    End Sub

    Private Sub cmdDir_Click(sender As Object, e As EventArgs) Handles cmdDir.Click
        FolderBrowserDialog1.ShowDialog()
        TxtDir.Text = FolderBrowserDialog1.SelectedPath
    End Sub

    Private Sub ListView_SelectedIndexChanged(sender As Object, e As EventArgs) Handles List.SelectedIndexChanged

    End Sub

    Private Sub TxtDir_TextChanged(sender As Object, e As EventArgs) Handles TxtDir.TextChanged

    End Sub
End Class


The text box that displays the directory is TxtDir, the directory select button is cmdDir and my ListView is called List.

Any help is appreciated :)

Thanks,
WhaleTrain

P.S I am a beginner in VB so that's probably why I'm not getting anywhere :D

Is This A Good Question/Topic? 0
  • +

Replies To: Question/Problem: Trying to get listview to show files

#2 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1379
  • View blog
  • Posts: 4,444
  • Joined: 25-September 09

Re: Question/Problem: Trying to get listview to show files

Posted 15 September 2012 - 12:48 PM

Have you added a column to your listview? Without a column, you won't see anything you add in the views detail.
Was This Post Helpful? 0
  • +
  • -

#3 WhaleTrain  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 15-September 12

Re: Question/Problem: Trying to get listview to show files

Posted 15 September 2012 - 01:31 PM

View PostCharlieMay, on 15 September 2012 - 12:48 PM, said:

Have you added a column to your listview? Without a column, you won't see anything you add in the views detail.


Thank-you for the very quick reply. I have added two columns to the form for 'File' and 'File Size' after realizing I had to. I have no idea why it isn't working :(
Was This Post Helpful? 0
  • +
  • -

#4 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1379
  • View blog
  • Posts: 4,444
  • Joined: 25-September 09

Re: Question/Problem: Trying to get listview to show files

Posted 15 September 2012 - 03:15 PM

OK, but I don't see anywhere where you're adding listviewitems to the listview. There are multiple ways of doing this but I prefer to build a listviewitem with the needed information and then add that to the listview.

Example

Dim lvi as New ListViewItem
lvi.Text = "This is the first column in your listview"
lvi.SubItems.Add("This is the second column")
'you can keep adding subitems as needed for more columns
'lvi.SubItems.Add("3rd Column")
'At this point you've only created the listviewitem and populated the column information. To then put this into the listview you would you
ListView1.Items.Add(lvi) 'add the listviewitem to the listview.


You should no see a row with information in 2 columns appear in your listview with 2 columns and details view.
Was This Post Helpful? 0
  • +
  • -

#5 WhaleTrain  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 15-September 12

Re: Question/Problem: Trying to get listview to show files

Posted 15 September 2012 - 04:15 PM

View PostCharlieMay, on 15 September 2012 - 03:15 PM, said:

OK, but I don't see anywhere where you're adding listviewitems to the listview. There are multiple ways of doing this but I prefer to build a listviewitem with the needed information and then add that to the listview.

Example

Dim lvi as New ListViewItem
lvi.Text = "This is the first column in your listview"
lvi.SubItems.Add("This is the second column")
'you can keep adding subitems as needed for more columns
'lvi.SubItems.Add("3rd Column")
'At this point you've only created the listviewitem and populated the column information. To then put this into the listview you would you
ListView1.Items.Add(lvi) 'add the listviewitem to the listview.


You should no see a row with information in 2 columns appear in your listview with 2 columns and details view.


I'm abit confused by that. So far I have this form with the code above:

https://s3.amazonaws.com/files.droplr.com/files_production/acc_60159/dPqO?AWSAccessKeyId=AKIAJSVQN3Z4K7MT5U2A&Expires=1347754451&Signature=15IvdMPqGpgECqLnRjutwFlz%2BeA%3D&response-content-disposition=inline%3B%20filename%2A%3DUTF-8%27%27Screenshot%2Bon%2B9.16.2012%2Bat%2B12.13.36%2BAM.png

I just have no idea at the minute where to take it.
Was This Post Helpful? 0
  • +
  • -

#6 lucky3  Icon User is offline

  • Friend lucky3 As IHelpable
  • member icon

Reputation: 224
  • View blog
  • Posts: 745
  • Joined: 19-October 11

Re: Question/Problem: Trying to get listview to show files

Posted 15 September 2012 - 10:24 PM

View PostWhaleTrain, on 15 September 2012 - 04:15 PM, said:

I just have no idea at the minute where to take it.


I wasn't able to see the screenshot of your app for some reason, but it doesn't matter. CharlieMay didn't wrote the working code for you (and no one else will do the work for you), but has showed you the way to do it. If you are puzzled where to implement this idea, it would be in the button click event handling method, where you select the desired file directory.
Was This Post Helpful? 0
  • +
  • -

#7 WhaleTrain  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 15-September 12

Re: Question/Problem: Trying to get listview to show files

Posted 16 September 2012 - 06:10 AM

View Postlucky3, on 15 September 2012 - 10:24 PM, said:

View PostWhaleTrain, on 15 September 2012 - 04:15 PM, said:

I just have no idea at the minute where to take it.


I wasn't able to see the screenshot of your app for some reason, but it doesn't matter. CharlieMay didn't wrote the working code for you (and no one else will do the work for you), but has showed you the way to do it. If you are puzzled where to implement this idea, it would be in the button click event handling method, where you select the desired file directory.


I can fully understand that, it's about learning and figuring out for myself not getting other people to do it as I wouldn't learn that way. At least I can figure out now where to implement the code and try again :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1