Setting column width of datagrid in winforms

Hello all,

The following is my join query through which I am showing the 3 columns in the datagrid as QuesGroup, Question and Answer. I want to set the column width and headertext in the datagrid at the runtime using winforms.

I ahave used :

dgUserResponse.PreferredColumnWidth property,but it sets the same width to all columns.

I have used the datagridcolumnStyle property.I have searched for that also but I got only for the simple query and not for the join query.

dgUserRsponse is my datagrid.

Can anybody please help me out ?

getUserResponse = “select g.QuesGroup,q.Question,u.Answer from Question q,UserResponse u,QuesGroup g where q.QuesId=u.QuesId and q.QuesGrpId=g.QuesGrpId and u.CandidateId=” & UserId & " order by u.ResId"

        cmdGetUserResponse = New OleDbCommand(getUserResponse, con)
        'drGetUserResponse = cmdGetUserResponse.ExecuteReader
        daGetUserResponse = New OleDbDataAdapter(cmdGetUserResponse)
        daGetUserResponse.Fill(dsGetUserResponse)                               dgUserResponse.DataSource=dsGetUserResponse.Tables(0).DefaultView


I’m sure its the above.


I have tried this statement also,but it doesnt support i.e it doesn’t show the column property of datagrid.I want to implement this in winforms 2003

Any other suggestion or how can I write the statement you have suggested.

Thanks in advance.

Do you not have access to a Columns Property within the designer properties? You should be able to add/remove and edit columns, and the width property (at least it is in c#) can be changed.


No there in no “columns” property in winforms .The “columns” property is in the Asp.Net web application and doing it in the winforms 2003.

So, any other solution is there to set the width property of the datagrid?

Thanks in advance.

Sorry I don’t really use VB.Net, I only use C# which does have a Columns property IIRC.

After a quick search I found:

with :

DataGrid1.TableStyles("Employees").GridColumnStyles("Title").Width = newwidth