473,398 Members | 2,389 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

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

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
1 1836
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Anita C | last post by:
Hi, How do I associate or map a specific column in a datatable to a particular element present in an xml document - to read into a datatable as well as write from the datatable to the xml element?...
0
by: Stuart Ferguson | last post by:
I am currently writing a windows application which uses DataGrid components to display some data. I am wanting to allow the user to resize the columns to display data that is longer than the...
2
by: Yama | last post by:
Hi, How can I make it resizable? For example: <pre> <!-- datagrid Header --> <table class="TableHeader" id="tblHeader" border="1" runat="server">
4
by: Steph | last post by:
Hi, With a database that stores the path of several images, i have: <ASP:TemplateColumn ...> <ItemTemplate> <ASP:Image id="thePicture" ImageUrl=' <% # DataBinder.Eval(Container.DataItem,...
1
by: jimb | last post by:
I can get the dropdownlist into the datagrid, and I can populate it, but I can't read it. Anybody have a working example of a dropdownlist in an editable grid? Thanks. -- .....
0
by: Lucvdv | last post by:
Maybe a stupid question, but how can you widen the last column of a datagrid at runtime (i.e. with the mouse)? It won't let me. The grid is wider than the form it is on, maybe the presence of a...
9
by: dli07 | last post by:
Hello, I'm trying to convert a piece of code that creates a dynamic vertical resizing bar in a table from internet explorer to firefox. It's based on a post from...
0
by: sheri | last post by:
how can I resize only one column in datagrid in .net 2005 ?
0
by: ashinamdev | last post by:
Hi I have a probelm I am using the datagrid control in my asp.net web page. I want to resize the datagrid column at runtime. User can be able to resize the column width according to his...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.