theniteowl
Programmer
Hi All,
I am using Visual Studio 12 and have created a Windows Forms application with a ListView control on the page.
I am trying to populate the ListView with two columns of data, File Name and Creation Date from a specified folder.
I keep getting errors when I try to use SubItems.Add to add the second columns data.
Error
'System.Windows.Forms.ListView' does not contain a definition for
SubItems' and no extension method 'SubItems' accepting a first argument of type 'System.Windows.Forms.ListView could be found (are you missing a using directive or an assembly reference?)
I have the following references set.
using System;
using System.Collections.Generic;
using System.IO;
using System.Windows.Forms;
I am a newbie with C# and Visual Studio and I might be missing something very simple.
I do get both column headers but cannot populate the second columns values.
Any help would be appreciated.
Thanks.
Trent
At my age I still learn something new every day, but I forget two others.
I am using Visual Studio 12 and have created a Windows Forms application with a ListView control on the page.
I am trying to populate the ListView with two columns of data, File Name and Creation Date from a specified folder.
I keep getting errors when I try to use SubItems.Add to add the second columns data.
Error
'System.Windows.Forms.ListView' does not contain a definition for
SubItems' and no extension method 'SubItems' accepting a first argument of type 'System.Windows.Forms.ListView could be found (are you missing a using directive or an assembly reference?)
I have the following references set.
using System;
using System.Collections.Generic;
using System.IO;
using System.Windows.Forms;
Code:
private void filllistView1()
{
DateTime dt;
listView1.Columns.Add("Filename", -2, HorizontalAlignment.Left);
listView1.Columns.Add("Date", -2, HorizontalAlignment.Left);
DirectoryInfo sourceInfo = new DirectoryInfo(StagingPath);
FileInfo[] sFiles = sourceInfo.GetFiles("*.*");
foreach (FileInfo file in sFiles)
{
dt = file.LastWriteTime;
listView1.Items.Add(file.Name);
listView1.SubItems.Add(file.LastWriteTime.ToString("MM/dd/yyyy H:mm:ss"));
}
}
I am a newbie with C# and Visual Studio and I might be missing something very simple.
I do get both column headers but cannot populate the second columns values.
Any help would be appreciated.
Thanks.
Trent
At my age I still learn something new every day, but I forget two others.