Question

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.

Was it helpful?

Solution

this.dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;

OTHER TIPS

Try adding behind that

dataGridView.AutoResizeColumns();

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top