recursion in datagridview not working
recursion in datagridview not working
recursion in datagridview not working
recursion in datagridview not working
recursion in datagridview not working
recursion in datagridview not working recursion in datagridview not working recursion in datagridview not working recursion in datagridview not working recursion in datagridview not working recursion in datagridview not working recursion in datagridview not working recursion in datagridview not working
recursion in datagridview not working recursion in datagridview not working
recursion in datagridview not working
Go Back  Xtreme Visual Basic Talk > > > recursion in datagridview not working


Reply
 
Thread Tools Display Modes
  #1  
Old 08-13-2009, 01:30 PM
jtammyg jtammyg is offline
Freshman
 
Join Date: Jun 2008
Posts: 36
Default recursion in datagridview not working


In my application I am selecting a folder path and then asking the user if he/she wants to display full path or file names only.

My problem arises when I want to insert the results in a datagridview. The datagridview has 2 columns:

column1 ----> shows file name

column2 ----> shows file size in MB.



with the below code I get the file name and then the file size on the same column one after the other

I want to show as follows:

File Name Size (MB)
sample.txt 1.2
myspreadsheet.xls 0.6
Seanie.bmp 0.8


What do I need to modify in order to achieve this?

Thanks a lot in advanced for your time

Tammy




Code:
Private Sub DisplayFiles(ByVal DirPath As String)


        Dim Dir As DirectoryInfo = New DirectoryInfo(DirPath)
        Dim Items As FileSystemInfo() = Dir.GetFileSystemInfos()
        Dim Files As String
        Dim RowInt As Integer = 1
        Dim ColInt As Integer = 1
        Dim Sizes As Double = 0

        Try

            DataGridView1.Columns.Add(0, "FileName") 'adds column to my datagrid
            DataGridView1.Columns.Add(1, "Size (MB)") 'adds column to my datagrid

            For Each Item As FileSystemInfo In Items


                Files = DirectCast(Item, FileInfo).FullName
                Sizes = DirectCast(Item, FileInfo).Length / 1024 / 1024



                DataGridView1.Rows.Add((Files.Substring(Files.LastIndexOf("\") + 1))) 'add row to datagrid

                DataGridView1.Rows.Add(Sizes) 'add row to datagrid


            Next


        Catch ex As Exception
        End Try



        Label2.Text = DataGridView1.Rows.Count - 1




    End Sub
Reply With Quote
  #2  
Old 08-13-2009, 02:48 PM
IUnknown's Avatar
IUnknown IUnknown is offline
Senior Contributor

Forum Leader
* Expert *
 
Join Date: Oct 2004
Location: Montréal
Posts: 1,135
Default

Use the FileInfo type instead of FileSystemInfo in your For Each loop so you won't need to cast them yourself while in the loop. The way you used the Add method will only add values to the first column of the DGV. Here is what the Top Secret VB.Net Programmer's Handbook says about DataRows : http://msdn.microsoft.com/en-us/libr...view.rows.aspx. You can see an example of the DataRows.Add method in the Remarks section.

Code:
For Each Item As FileInfo In Items
  DataGridView1.Rows.Add(Item.FullName, Item.Length / 1048576)
Next
HTH,
<iunknown />
__________________
win7 : vs 2008 : .Net 3.5
Reply With Quote
  #3  
Old 08-13-2009, 03:06 PM
jtammyg jtammyg is offline
Freshman
 
Join Date: Jun 2008
Posts: 36
Default

IUnknown,

It works great!!!

I cannot believe I spend the last 3 hours trying to figure this one out.

Thank you soooo much for your help and time!!

best regards,

Tammy
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
recursion in datagridview not working
recursion in datagridview not working
recursion in datagridview not working recursion in datagridview not working
recursion in datagridview not working
recursion in datagridview not working
recursion in datagridview not working recursion in datagridview not working recursion in datagridview not working recursion in datagridview not working recursion in datagridview not working recursion in datagridview not working recursion in datagridview not working
recursion in datagridview not working
recursion in datagridview not working
 
recursion in datagridview not working
recursion in datagridview not working
 
-->