我构建应用程序并将文件添加到我的 ListView,我希望每次添加的最后一个文件都会强调,所以在我添加的 Foreach 语句lvFiles.Items[lvFiles.Items.Count - 1].Selected = true;
中,但在这种情况下,我的 ListView 中的所有文件都强调,而不仅仅是最后一个
List<string> filesList
foreach (string fileName in filesList)
{
FileInfo fileInfo = new FileInfo(fileName);
if (checkFileCreationDate(fileInfo))
{
if (editcap.isWiresharkFormat(fileInfo.FullName))
{
if (editcap.isLibpcapFormat(fileInfo.FullName))
{
addFileToListBox(fileInfo.FullName, capinfos.getFileDuration(fileInfo.FullName));
}
else if (!editcap.isLibpcapFormat(fileInfo.FullName))
{
fileToAdd = editcap.getNewFileName(fileInfo.FullName);
if (new FileInfo(fileToAdd).Exists && !fileInfo.Exists)
{
addFileToListBox(fileToAdd, capinfos.getFileDuration(fileInfo.FullName));
}
}
}
}
}
private void addFileToListBox(string filePath, string duration)
{
item = new ListViewItem(new string[] { new FileInfo(filePath).Name, duration, "Waiting" });
item.Tag = new FileInfo(filePath).FullName;
}