我有一个由linq查询填充的datagridview控件:
public static IQueryable SearchByDepartmentNameInfo(string deptName)
{
ExamineDataContext dc = new ExamineDataContext();
var queryResult = from q in dc.GetTable<Question>()
where q.Topic.Module.Department.DepartmentName.Equals(deptName)
join s in dc.Solutions
on q.QuestionID equals s.QuestionID
into qs // note grouping
select new
{
Module = q.Topic.ModuleTitle,
Topic = q.TopicName,
Question = q.QuestionText,
QuestionType = q.QuestionType,
};
return queryResult;
}
dataGridView1.DataSource = Repository.SearchByDepartmentNameInfo("Computer Science");
我希望datagridview根据查询返回的数据自动调整列的大小。
非常感谢。
答案 0 :(得分:3)
this.dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
答案 1 :(得分:0)
尝试添加
dataGridView.AutoResizeColumns();