2016-09-21 35 views
0

我的目标如下: 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中列字符串动态 - 不工作

After clicking OK the previous window is closed and the user is taken to the main form shown in this picture. The previously mentioned source file and the destination directory are shown in the table.

我使用下面的代码显示在表格中输入文件&目录:

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(第一个图片)类中的一个函数。正确的文本保存在数组中,但未在表格中显示。请帮忙!

+0

你添加必要的列到你的ListView? – TaW

回答

0

lvd变量没有被使用。您必须将'lvd' - 控制添加到您的主视图。您可以使用Designer进行设置,也可以在“FilePickerDialog”的对话框结果中将结果分配给数据网格。

您的MainView一些伪代码

void Config_Clicked() 
{ 
    ConfigDlg dlg = new ConfigDlg(); 
    if(dlg.ShowDialog() == OK) 
    { 
     this.myListView1.Items.Add(dlg.userInput[0]); 
    } 
} 
+0

非常感谢。有效。 – Dovile

+0

很好听;-)我不会期望从我所有的伪代码^^ – Mat