我正在使用.net 3.5 - 我嘗試列表框項目到文本文件時出現問題。我使用此代碼:如何保存文本文件中的列表框項目
if (lbselected.Items.Count != 0) {
string Path = Application.StartupPath + "\\ClientSelected_DCX.txt";
StreamWriter writer = new StreamWriter(Path);
int selectedDCXCount = System.Convert.ToInt32(lbselected.Items.Count);
int i = 0;
while (i != selectedDCXCount) {
string selectedDCXText = (string)(lbselected.Items[i]);
writer.WriteLine(selectedDCXText);
i++;
}
writer.Close();
writer.Dispose();
}
MessageBox.Show("Selected list has been saved", "Success", MessageBoxButtons.OK);
此訂單時出現的錯誤:
string selectedDCXText = (string)(lbselected.Items[i]);
錯誤是:
無法轉換類型的對象的sampleData'爲類型「系統.String' 請幫我
雖然他可能想整個對象。 – 2011-05-10 04:53:17
感謝它正在保存,但它正在將列表項目寫入文本文件其不保存項目名稱,但將此行保存在文本文件中Realtime_ALL.Form1 + SampleData Realtime_ALL.Form1 + SampleData – voipservicesolution 2011-05-10 04:55:59