我的目標如下: The user enters the stuff as shown in this picture. The 3 items (source file, destination directory and if file exists) are saved in a string array. User clicks OK.顯示ListView中列字符串動態 - 不工作
我使用下面的代碼顯示在表格中輸入文件&目錄:
private void okButton_Clicked(object sender, EventArgs e)
{
//saving user's input
userInput = new string[3];
userInput[0] = sourceFileTextBox.Text;
userInput[1] = destinationDirComboBox.SelectedItem.ToString();
userInput[2] = ifFileExistsComboBox.SelectedItem.ToString();
//creating a new ListView object - the object is derived from the ListView Class
and has absolutely nothing in the constructor or anywhere
Classes.ListViewDerivative lvd = new Classes.ListViewDerivative();
ListViewItem item1 = new ListViewItem(userInput[0]);
item1.SubItems.Add(userInput[1]);
lvd.Items.AddRange(new ListViewItem[] { item1 });
this.DialogResult = DialogResult.OK;
this.Hide();
}
它不起作用。無論我把這段代碼放在哪裏,表格都是空的 - 我試圖將這個自適應代碼放在ListViewDerivative構造函數中,這是ListViewDerivative類和editFileEntry(第一個圖片)類中的一個函數。正確的文本保存在數組中,但未在表格中顯示。請幫忙!
你添加必要的列到你的ListView? – TaW