Results 1 to 2 of 2

Thread: [RESOLVED] [2005] DataGridView misbehaving

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Location
    Manchester, England
    Posts
    255

    Resolved [RESOLVED] [2005] DataGridView misbehaving

    Hello,
    I think I've been looking at this for too long, and can't see where the problem is.
    I'm basically going through a folder, and adding file path and file name data to a DataGridView, along with a column to ask the user to confirm that they want to delete the file shown in the grid.
    Code:
    For intCounter As Integer = 0 To strFiles.Length - 1
    
        Me.prgFilesInFolderProgress.Value = intCounter
    
        txtFileName = strFiles(intCounter)
        dteFileCreated = Directory.GetCreationTime(strFiles(intCounter)).Date
        dteFileModified = Directory.GetLastWriteTime(strFiles(intCounter)).Date
    
        If (dteFileCreated.Date >= dteSelected And dteFileCreated.Date <= dteSelectedTo) Or _
            (dteFileModified.Date >= dteSelected And dteFileModified.Date <= dteSelectedTo) Then
    
            If Me.DataGridView1.Visible = False Then
                Me.DataGridView1.Visible = True
            End If
    
            intDataGridRows += 1
    
            Me.DataGridView1.Rows.Add()
    
            'MsgBox("intDataGridRows = " & intDataGridRows.ToString & vbCrLf & _
            '        "Rows in DataGridView = " & Me.DataGridView1.Rows.Count.ToString)
    
            Me.DataGridView1.Item(0, intCounter).Value = txtFileName
            Me.DataGridView1.Item(1, intCounter).Value = True
    
        End If
    
    Next
    What I'm finding is that if I use the code as it is, I get something that is half-way what I need, but if I replace a couple of lines ...
    Code:
            Me.DataGridView1.Item(0, intDataGridRows).Value = txtFileName
            Me.DataGridView1.Item(1, intDataGridRows).Value = True
    .... I get loads of blank rows, and the bottom row of the grid is the last file it encountered in the For .... Next loop.
    At home - VB.NET 2005/2008 Express, Visual Web Developer 2005 Express
    At work - VS 2008 Standard (VB)
    .NET 2.0/3.5


    Visual Studio Express Learning Centre | How do I videos | MSDN VB Express Forum | MSDN VB Developer Centre

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Location
    Manchester, England
    Posts
    255

    Re: [2005] DataGridView misbehaving

    Cracked it ...

    Code:
    Me.DataGridView1.Item(0, intDataGridRows - 1).Value = txtFileName
    Me.DataGridView1.Item(1, intDataGridRows - 1).Value = True
    At home - VB.NET 2005/2008 Express, Visual Web Developer 2005 Express
    At work - VS 2008 Standard (VB)
    .NET 2.0/3.5


    Visual Studio Express Learning Centre | How do I videos | MSDN VB Express Forum | MSDN VB Developer Centre

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width