2015-09-06 67 views
0

我是新手,我試圖簡單地結合HashSet爲DataGridView中的DataSource,但仍然有GridView綁定的HashSet到DataGridView的數據源C#

 dataGridViewBookList.DataSource = null; 
    dataGridViewBookList.DataSource = bookContainer; 

創建哈希集合

bookContainer = new HashSet<BookModel>(); 
    dataGridViewBookList.DataSource = bookContainer; 

BookModel類的任何項目

class BookModel 
    { 
     public string Name { get; set; } 
     public uint Year { get; set; } 
     public string Series { get; set; } 
     public string Pulbisher { get; set; } 
     public string Author { get; set; } 
     public string Language { get; set; } 
     public uint PagesCount { get; set; } 
    } 

請幫忙綁定h灰設置爲GridView。對不起,我是C#的新手。
非常感謝。

回答

0

試試這個

var book = new BookModel//fill it with your data 
     { 
      Author = "a", 
      Language = "l", 
      Name = "n", 
      PagesCount = 0, 
      Pulbisher = "p", 
      Series = "s", 
      Year = 1990 
     }; 
     var list=new List<BookModel>(); 
     list.Add(book); 
     var bookContainer = new HashSet<BookModel>(list);//you have to pass list to HashSet constructor 

     dataGridViewBookList.DataSource = bookContainer.ToList(); 
0

你可以嘗試ToList()用於bookContainer

相關問題