SonicBoomAu Posted March 9, 2005 Posted March 9, 2005 Hi All, What I am tring to find out is if it is possible to set a single columns width during runtime within a datagrid. For Example. I load the information straight from an Access database on the form load event. The datagrid has the PreferredColumnWidth set to 100. I want to change the second column width to 300. Is this possible???. Thanks in advance. :) Quote Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -- Rick Cook, The Wizardry Compiled
SonicBoomAu Posted March 13, 2005 Author Posted March 13, 2005 Anyone. I know the name of the column. I have read previous threads and they all seem to state that you must name manually set each column name and width. This is what I would prefer not do do as the are some 30+ columns. Any help is appreciated. Quote Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -- Rick Cook, The Wizardry Compiled
SonicBoomAu Posted March 15, 2005 Author Posted March 15, 2005 After many hours searching the Internet :( , I was able to find where I wen't wrong. :o Here is the bit of Code I found: Dim myConnection As New SqlConnection(myConnectString) myConnection.ConnectionString = myConnectString myConnection.Open() Dim da As SqlDataAdapter = New SqlDataAdapter("Select * from tblTest", myConnection) Dim ds As New DataSet da.Fill(ds, "tbltest") DataGrid1.DataSource = ds.Tables("tbltest") 'Changes the datagrid size Dim tableStyle1 As New DataGridTableStyle tableStyle1.MappingName = "tbltest" Me.DataGrid1.TableStyles.Clear() Me.DataGrid1.TableStyles.Add(tableStyle1) Me.DataGrid1.TableStyles("tbltest").GridColumnStyles(0).Width = 100 Me.DataGrid1.TableStyles("tbltest").GridColumnStyles(1).Width = 200 myConnection.Close() I discovered that you don't need to adjust every column but can place the Columns headertext in the "GridColumnStyles()" area. I.E. GridColumnStyles(1) becomes GridColumnStyles("Equip0"). Hope this helps the next person. :D Quote Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -- Rick Cook, The Wizardry Compiled
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.