2013-07-29 21 views
1

我正試圖向現有集合添加一個新行/值。但是在添加該行後它顯示相同的舊結果。將行添加到不能正常工作的集合

//代碼

Using CustomActionWorkflow As New CustomActionWorkflow() 
     CustomActionWorkflow.WorkflowId = Me.WorkflowId 
     CustomActionWorkflow.CustomActionId = Me.CustomActionId 
     Me.CustomActionsController.CustomActionsWorkflowCollection.ToList().Add(CustomActionWorkflow) 
End Using 

在那裏我錯了嗎?

+0

「CustomActionsWorkflowCollection」proeprty的類型是什麼? – nemesv

+0

@nemesv:它的屬性集合。 – iamCR

回答

1

ToList()函數爲您提供IEnumerable集合的新副本。您嘗試添加到您沒有參考的列表中。

嘗試,如果CustomActionsWorkflowCollection有添加方法

Me.CustomActionsController.CustomActionsWorkflowCollection.Add(CustomActionWorkflow) 

,或者收集可設置

var list = Me.CustomActionsController.CustomActionsWorkflowCollection.ToList(); 
list.Add(CustomActionWorkflow); 
Me.CustomActionsController.CustomActionsWorkflowCollection = list; 

但最後還不是怎麼一回事,因爲創造了許多臨時列表的一個很好的解決方案。

+0

任何示例代碼? – iamCR

+0

你是否要我添加而不轉換爲列表? – iamCR

+0

給你一個完整的答案,我們需要知道Me.CustomActionsController.CustomActionsWorkflowCollection – Vasiliy