Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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. :)

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

Posted

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.

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

Posted

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

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

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