我不完全確定這裏發生了什麼 - 我試圖調試,但不能真正想出任何解釋爲什麼沒有寫入我的datagridview。輸出沒有被寫入我的代碼中的DGV
有人有什麼想法嗎?
public partial class CleanPathResults : Form
{
public CleanPathResults()
{
InitializeComponent();
}
public void RenameFolder(string folderName)
{
string regPattern = (@"[~#&$!%+{}]+");
string replacement = "";
List<string> normal = new List<string>();
Regex regExPattern = new Regex(regPattern);
dataGridView1.Rows.Clear();
List<string> cleanDirNames = new List<string>();
try
{
if (regExPattern.IsMatch(folderName))
{
string cleanup = regExPattern.Replace(folderName, replacement);
System.IO.Directory.Move(folderName, cleanup);
DataGridViewRow grid = new DataGridViewRow();
grid.CreateCells(dataGridView1);
grid.Cells[0].Value = folderName;
grid.Cells[1].Value = cleanup;
dataGridView1.Rows.Add(grid);
folderName = cleanup;
cleanDirNames.Add(cleanup);
}
else
{
normal.Add(folderName);
}
}
catch(Exception e)
{
throw;
}
DirectoryInfo di = new DirectoryInfo(folderName);
DirectoryInfo[] diArr = di.GetDirectories();
List<string> subdirectories = new List<string>();
try
{
foreach (DirectoryInfo subdir in diArr)
{
subdirectories.Add(subdir.ToString());
}
}
catch(Exception e)
{
throw;
}
try
{
foreach (string folder in subdirectories)
{
string sF = folder;
RenameFolder(folderName + "\\" + sF);
}
}
catch(Exception e)
{
throw;
}
}
private void button1_Click_1(object sender, EventArgs e)
{
Application.Exit();
}
}
我不打任何錯誤 - 應用程序做什麼它應該做的(在這種情況下,確保文件夾名稱不包含在正則表達式定義的無效字符)......然而這只是輸出不在dgv上顯示的問題。
任何幫助,將不勝感激。
不存在匹配正則表達式 - 該應用程序糾正它。但是,在文件夾清理了無效字符之後,我的dgv中的輸出應該是具有無效字符的舊路徑以及清除了無效字符的新路徑。這似乎並沒有發生...... – yeahumok 2010-07-22 17:13:42
好,所以我在if(regex.Ismatch(folderName))語句中設置了一個斷點。它創建新的行...但我沒有注意到,在這一行:dataGridView1.Rows.Add(grid);有一個指數爲-1?這也許是爲什麼它不創造任何東西?奇怪的是,當我在細胞上放置斷點時,數值顯示正確。看來信息正確地進入,但是它只是沒有寫入單元格。 – yeahumok 2010-07-22 17:17:36
-1哪裏?行? – 2010-07-22 17:19:26