Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hello,

 

This is a follow up to the "datagrid on windows forms" question.

 

I looked at the following page that tlaks about setting column widths of a datagrid

 

http://www.syncfusion.com/faq/winforms/search/792.asp

 

and modified my code as follows

 

Dim style As New DataGridTableStyle

style.MappingName = "providers_list"

style.GridColumnStyles(0).Width = 150

style.GridColumnStyles(1).Width = 200

style.GridColumnStyles(2).Width = 300

dtgCourses.TableStyles.Add(style)

dtgCourses.DataSource = ds.Tables(0)

dtgCourses.Refresh()

 

I get an index error when I run this, even though the selection sql has more then 3 return fields for each record.

 

How can I set the column widths of a datagrid from the code behind?

 

Thanks,

 

Burak

Posted

Burak,

 

You need to declare grid column styles after the style.mappingName statement, eg Dim FirstNameCol As New DataGridTextBoxColumn().

Then set the various properties of the FirstNameCol column style i.e. .Width = 100, etc.

Then, add the new column style to the DataGridTableStyle collection using

style.GridColumnStyles.Add(FirstNameCol), and so on for each column style needed in the datagrid.

 

Hope this helps

Posted

One more thing, you need to delete the following

 

"style.GridColumnStyles(0).Width = 150

style.GridColumnStyles(1).Width = 200

style.GridColumnStyles(2).Width = 300"

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...