2013-10-29 111 views
0

我如何使用Addrange填充對象的列表視圖。對象是:通過AddRange填充列表視圖

public class Cable : StateObject 
    {  

    public int Id { get; set; } 
    public int CablePropertyId { get; set; } 
    public int Item { get; set; } 
    public int TagNo { get; set; } 
    public string GeneralFormat { get; set; } 
    public string EndString { get; set; } 
    public string CableRevision { get; set; } 
    public string FromBay { get; set; } 
    public string FromPanel { get; set; }  
} 

感謝

+1

創建一個ListViewItem的數組,並將其添加到你的列表視圖。 –

回答

0

嗯,是的AddRange在列表中定義。

你可以這樣做:

var list_view = new ListView(); 
var some_array = new string[] {"1","2", "3", "4"}; 
var list_of_strings = new List<string>() ; 
list_of_strings.AddRange(some_array); 
list_view.ItemsSource = list_of_strings; 

因此,添加範圍接受一個I​​Enumerable。

在任何時候,上面的例子是一個有點傻,因爲你,因爲你可以簡單地這樣做:

list_view.ItemsSource = some_array; 

避免了list_of_stringsAddRange的需要。