我是新手我试图仅将HashSet
绑定为DataGridView的DataSource
,但仍有GridView
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; }
}
请帮助将哈希集绑定到GridView。对不起,这个问题我是C#的新手 非常感谢你。
答案 0 :(得分:0)
您可以尝试使用bookContainer的ToList()
答案 1 :(得分: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();