我有很多与我的项目有关的问题,我真的不知道从哪里开始。首先,我得到一个错误“非静态字段,方法或属性需要对象引用”。它强调了retPath(该行:DriveRecursion_results.DriveRecursion(retPath);)。我不知道如何解决这个问题。ListView和文件输出的问题
我仍然难住的另一件事是如何填充我的Windows窗体上的列表视图。我想要的是需要重命名的文件列表(与我列表中的所有文件列表相比较)。
任何人都可以帮忙吗?现在我一直在苦苦挣扎几个小时。
这里是我的代码:
Form1.cs中:
namespace FileMigration
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
FolderSelect("Please select:");
}
public string FolderSelect(string txtPrompt)
{
//Value to be returned
string result = string.Empty;
//Now, we want to use the path information to population our folder selection initial location
string initialCheckoutPathDir = (@"C:\");
System.IO.DirectoryInfo info = new System.IO.DirectoryInfo(initialCheckoutPathDir);
FolderBrowserDialog FolderSelect = new FolderBrowserDialog();
FolderSelect.SelectedPath = info.FullName;
FolderSelect.Description = txtPrompt;
FolderSelect.ShowNewFolderButton = true;
if (FolderSelect.ShowDialog() == DialogResult.OK)
{
string retPath = FolderSelect.SelectedPath;
if (retPath == null)
{
retPath = "";
}
DriveRecursion_Results ds = new DriveRecursion_Results();
ds(retPath);
result = retPath;
//Close this form.
}
return result;
}
}
}
这里是DriveRecursion_Results.cs:
namespace FileMigration
{
public partial class DriveRecursion_Results : Form
{
public DriveRecursion_Results()
{
InitializeComponent();
}
private void fileOutput_SelectedIndexChanged(object sender, EventArgs e)
{
}
public void DriveRecursion(string retPath)
{
// string[] files = Directory.GetFiles(retPath, "*.*", SearchOption.AllDirectories);
string pattern = " *[\\~#%&*{}/<>?|\"-]+ *";
string replacement = "";
Regex regEx = new Regex(pattern);
string[] fileDrive = Directory.GetFiles(retPath, "*.*", SearchOption.AllDirectories);
List<string> filePath = new List<string>();
foreach (string fileNames in fileDrive)
{
if (regEx.IsMatch(fileNames))
{
filePath.Add(fileNames);
//I tried adding my listview (fileOptions) here but I cannot for some reason
}
}
}
}
}
任何帮助将真正理解:(没有任何人有任何想法关于如何更改我的代码使其实际上有效?
编辑:现在这两种方法都是非静态的,并照顾了我用retPath得到的错误。然而,任何人都有问题#2的想法,让列表视图仅显示需要重命名的文件的输出? – yeahumok 2010-06-22 20:48:08
你有什么代码已经尝试添加项目到你的列表视图?现在该方法不是静态的,你应该只能调用ListView.Items.Add(“Item”); – 2010-06-22 20:53:40
我这样做 - 但是当我运行我的应用程序,我只有对话选择驱动器和文件夹,而不是列表。是它的B/C我没有把私人无效的任何东西fileOutput_SelectedIndexChanged(对象发件人,EventArgs E)?如果是这种情况,我需要在那里确保我的应用程序知道要显示带有需要更改的文件输出的列表视图。 – yeahumok 2010-06-22 20:56:40