burak Posted March 15, 2004 Posted March 15, 2004 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 Quote
bdubon Posted March 18, 2004 Posted March 18, 2004 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 Quote
bdubon Posted March 18, 2004 Posted March 18, 2004 One more thing, you need to delete the following "style.GridColumnStyles(0).Width = 150 style.GridColumnStyles(1).Width = 200 style.GridColumnStyles(2).Width = 300" Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.