473,403 Members | 2,270 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,403 software developers and data experts.

Column width in DataGrid

Hi, how've you been?

How can I do to set the column width of a datagrid to fix the width of the
text in each column?

Thanks.

Jaime Lucci
ja********@hotmail.com
Nov 21 '05 #1
2 2553
"Jaime Lucci" <ja********@hotmail.com> schrieb:
How can I do to set the column width of a datagrid to fix the width of the
text in each column?


5.52 How can I autosize a column in my datagrid?
<URL:http://www.syncfusion.com/FAQ/WindowsForms/FAQ_c44c.aspx#q877q>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #2
This code will not solve your problem entirely, but may put you on the right
track. In my case I had a dozen different data grids and didn't want to
specify the names and widths of every collumn in every one of them so I just
created a function to set all of the collumns to a longer width. It is much
simpler to maintain but doesnt give you as much flexibility.

Public Shared Sub SetTableStyle(ByRef MyDataGrid As DataGrid)

'************************************************* **********************
' Public method
' called by all forms using datagrids
' defines consistent table styles in one place

'************************************************* **********************
Dim objTableStyle As New DataGridTableStyle
objTableStyle.AlternatingBackColor = System.Drawing.Color.OldLace
'set every other datagrid line to a seperate color to make it easier to read
objTableStyle.PreferredColumnWidth = 150
MyDataGrid.TableStyles.Add(objTableStyle)
End Sub

You can also specify individual collumns, identified by the collumn name in
your dataset. This can be done programatically, or through the TableStyles
Collectin in the designer.
"Jaime Lucci" <ja********@hotmail.com> wrote in message
news:On**************@tk2msftngp13.phx.gbl...
Hi, how've you been?

How can I do to set the column width of a datagrid to fix the width of the
text in each column?

Thanks.

Jaime Lucci
ja********@hotmail.com

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Hajash | last post by:
hi all, how do i set the width of a column in a datagrid.Please help.Thanks in advance. regards, hajash
0
by: Lalit Bhatia | last post by:
Hi, In Datagrid, while setting width of column through GridColumnStyles collection. width does not set to exact width that I am setting in my code. If I set width to 13, it is changed to 130 or...
24
by: Mike L | last post by:
This is for a Win form, in C# 2005. I want to load a datagrid, make some columns width 0, and then clean out the record I added. I get the error message, ""Index was out of range. Must be...
1
by: Drew | last post by:
Hey, thanks in advance for helping me out with my problem: I have a datagrid which is embedded in another datagrid. The datagrid is filled directly by a dataset generated from a sql query. So...
0
by: cedoucette | last post by:
I just wrote code to support sortable columns in a datagrid. It seems to work fine; but, it doesn't look right. The problem is that I have a generic style for links and a different style for the...
17
by: Mike Fellows | last post by:
im trying (unsucessfully) to add a checkbox column to my datagrid i basically have a datagrid that im populating from a dataset Me.DataGrid1.DataSource = ds.Tables(0) the datagrid then has 5...
1
by: Jorge | last post by:
Hello All I am trying to preserve the width of column in a datagrid made by the user. On form load i use this <code> Me.DataGrid2.TableStyles("artenc").GridColumnStyles (0).Width = 30...
6
by: Agnes | last post by:
I understand it is impossible, but still curious to know "Can I freeze several column in the datagrid, the user can only scroll the first 3 columns (not verical), for the rest of the coulumn, it is...
6
by: cr113 | last post by:
I'm trying to set the column widths for a datagrid. You'd think it would be easy. I looked it up in google and the first thing I found looked promising: datagrid1.columns(0).width = 2000...
2
by: Charleees | last post by:
Hi all, I have a DataGrid with Template Columns..... There are LAbels,Linkbuttons in the Single Row.. I have to set the Constant Column width for those Template Columns in Grid... Wat...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.