1

我有一个由 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 根据查询返回的数据自动调整列的大小。

非常感谢帮助。

4

2 回答 2

3

this.dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;

于 2009-05-03T08:09:05.600 回答
0

尝试在后面添加

dataGridView.AutoResizeColumns();

于 2009-05-05T08:44:43.670 回答