views:

1545

answers:

2

Hello,

I have a datagridview control that is populated by a linq query:

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");

I want the datagridview to automatically resize the columns based on the data returned from the query.

Help appreciated greatly.

+2  A: 

this.dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;

Goober
A: 

Try adding behind that

dataGridView.AutoResizeColumns();

mirekys