将 HashSet 绑定到 DataGridView 数据源 C#
Bind HashSet to DataGridView DataSource C#
我是新手 我尝试简单地将 HashSet
绑定为 DataGridView 的 DataSource
,但在 GridView
中仍然有任何项目
dataGridViewBookList.DataSource = null;
dataGridViewBookList.DataSource = bookContainer;
正在创建哈希集
bookContainer = new HashSet<BookModel>();
dataGridViewBookList.DataSource = bookContainer;
BookModel class
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# 的新手。
非常感谢。
你能为 bookContainer 尝试 ToList()
试试这个
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();
我是新手 我尝试简单地将 HashSet
绑定为 DataGridView 的 DataSource
,但在 GridView
dataGridViewBookList.DataSource = null;
dataGridViewBookList.DataSource = bookContainer;
正在创建哈希集
bookContainer = new HashSet<BookModel>();
dataGridViewBookList.DataSource = bookContainer;
BookModel class
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# 的新手。
非常感谢。
你能为 bookContainer 尝试 ToList()
试试这个
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();