By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,239 Members | 1,503 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,239 IT Pros & Developers. It's quick & easy.

One line of code not working : susposed to resize datagrid column..

P: n/a
I'm following a sql/vb tutorial which contains the following code which
is meant to resize the datagrid view so that the columns take the
correct width for the content within them.

It doesn't work the syntax seems to be nonsense according to VS2005 so
can someone suggest what I need to replace it with?
Thanks...
dgvStatus.AutoSizeColumns
(DataGridViewAutoSizeColumnCriteria.HeaderAndDispl ayedRows)

p.s. dgvStatus is the name of a datagrid control i have on the form.

Apr 5 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hi,

Use this to make the column resize its width.

Imports System.Data.SqlClient

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim strConn As String = _
"Server = .\SQLEXPRESS;Database = NorthWind; Integrated Security
= SSPI;"
Dim conn As New SqlConnection(strConn)
Dim da As New SqlDataAdapter("Select * from Categories", conn)
Dim dt As New DataTable

da.Fill(dt)
DataGridView1.AutoSizeRowsMode =
DataGridViewAutoSizeRowsMode.AllCells
DataGridView1.DataSource = dt

With DataGridView1.Columns("Description")
.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
End With

With DataGridView1.Columns("Image")
.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
End With
End Sub
End Class

This will make the column multi line

Imports System.Data.SqlClient

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim strConn As String = _
"Server = .\SQLEXPRESS;Database = NorthWind; Integrated Security
= SSPI;"
Dim conn As New SqlConnection(strConn)
Dim da As New SqlDataAdapter("Select * from Categories", conn)
Dim dt As New DataTable

da.Fill(dt)
DataGridView1.AutoSizeRowsMode =
DataGridViewAutoSizeRowsMode.AllCells
DataGridView1.DataSource = dt

With DataGridView1.Columns("Description")
.Width = 100
.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
.DefaultCellStyle.WrapMode = DataGridViewTriState.True
End With

With DataGridView1.Columns("Image")
.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
End With
End Sub
End Class
Ken
----------------
<ga********@myway.com> wrote in message
news:11**********************@e56g2000cwe.googlegr oups.com...
I'm following a sql/vb tutorial which contains the following code which
is meant to resize the datagrid view so that the columns take the
correct width for the content within them.

It doesn't work the syntax seems to be nonsense according to VS2005 so
can someone suggest what I need to replace it with?
Thanks...
dgvStatus.AutoSizeColumns
(DataGridViewAutoSizeColumnCriteria.HeaderAndDispl ayedRows)

p.s. dgvStatus is the name of a datagrid control i have on the form.

Apr 5 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.