我的目标如下: 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