Setting column width of datagrid in vb.net 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 vb.net 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

dgUserResponse.Columns[0].Width

I’m sure its the above.

hello,

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 vb.net 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.

hello,

No there in no “columns” property in vb.net winforms .The “columns” property is in the Asp.Net web application and doing it in the vb.net 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:

http://support.microsoft.com/kb/811203

with :


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