[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.
Re: [2005] DataGridView misbehaving
Cracked it ...
Code:
Me.DataGridView1.Item(0, intDataGridRows - 1).Value = txtFileName
Me.DataGridView1.Item(1, intDataGridRows - 1).Value = True