您的ListView
控件是否有任何列設置?如果沒有,內容將不可見。嘗試:
private void ListClientButton_Click(object sender, EventArgs e)
{
ListClientsBox.Columns.Add("Full name");
CDB.ListClients(ListClientsBox.Items);
}
編輯:
我已經運行一些測試,你在發佈註釋代碼似乎要被罰款。你可能只需要調整幾個ListView的性質,取決於顯示你的目標爲:
// perpare ListView beforehand
this.listView.Columns.Add("First name");
this.listView.Columns.Add("Email");
this.listView.Columns.Add("Country");
this.listView.View = View.Tile;
// if tile height is too small, some data might not be visible
this.listView.TileSize = new Size(180, 50);
// sample data
var people = new[]
{
new { FirstName = "John", Email = "[email protected]", Country = "USA" },
new { FirstName = "Betty", Email = "[email protected]", Country = "Canada" },
new { FirstName = "Steven", Email = "[email protected]", Country = "Brazil" },
};
foreach (var person in people)
{
ListViewItem item = new ListViewItem(person.FirstName);
item.SubItems.Add(person.Email);
item.SubItems.Add(person.Country);
this.listView.Items.Add(item);
}
這是怎樣的ListView樣子,既View.Tile
和View.Details
: ![ListView examples](https://i.stack.imgur.com/grklK.png)
是ListView.Items也實現了合同IList。所以它應該可以在你的ListClients方法中被替代。 IList只是任何希望被用作IList的類必須實現的合同。例如ListViewItemCollection http://msdn.microsoft.com/en-us/library/system.windows.forms.listview.listviewitemcollection%28v=vs.80%29.aspx – Gishu 2011-04-26 07:27:26
我已經嘗試過,但在列表視圖中的形式它只將對象名稱放在第一列 – flo 2011-04-30 03:24:58