2016-09-21 36 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