473,839 Members | 1,414 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how do i set the width of a column in a datagrid

hi all,

how do i set the width of a column in a datagrid.Please help.Thanks in

Nov 16 '05 #1
2 1719

Have a look at the datagridtextbox column width (or any other style
columncomponent )


Be aware that this does not fix it.

I hope this helps,

Nov 16 '05 #2
Hi Hajash,

if it is a web datagrid you can set it by

this.DataGrid1. Columns[x].ItemStyle.Widt h = xx;

If it is windows forms here is a sample:

To set a column width, your datagrid must be using a non-null
DataGridTableSt yle. Once this is in place, you can set the column width
by first getting the tablestyle and then using that object to obtain a
column style with which you can set the width. Here are some code
snippets showing how you might do this.

//.... make sure your DataGrid is using a tablestyle
dataGrid1.DataS ource = _dataSet.Tables["customers"];
DataGridTableSt yle dgts = new DataGridTableSt yle();
dgts.MappingNam e = "customers" ;
dataGrid1.Table Styles.Add(dgts );

//method to set a column with by colnumber
public void SetColWidth(Dat aGridTableStyle tableStyle, int colNum, int


tableStyle.Grid ColumnStyles[colNum].Width = width;
tableStyle.Data Grid.Refresh();
catch{} //empty catch .. do nothing

// here is how you might call this method
private void button1_Click(o bject sender, System.EventArg s e)
DataGridTableSt yle tableStyle = dataGrid1.Table Styles["customers"];
SetColWidth(tab leStyle, 1, 200);
Santiago Corredoira
Hajash wrote:
hi all,

how do i set the width of a column in a datagrid.Please help.Thanks in


Nov 16 '05 #3

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

Similar topics

by: Prateek | last post by:
Hi, How can I change the width of a column in datagrid control? TIA Prateek
by: Stephen | last post by:
I have a datagrid and i'm trying to fix the width of one of the columns to be exactly 300px. My problem is that one of the records fields(CompanyName) is really long and has no spaces so it streches the whole datagrid accross the screen. Has anyone else ever experienced this problem and is there any way of fixing it. Basically my datagrid is streching to about 120% because of this one record. Would love to work out how I can change this...
by: web1110 | last post by:
Hi y'all, I have resized the columns in a DataGrid and I want to set the width of the DataGrid to fit the columns. Just summing the column widths is too short due to the grid and gray row selection column on the left. I have the widths of the columns. What other values do I need to include in the DataGrid width? Thanx,
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 if set to 208, it changes to 206. On changing width of column I am resizing the width of grid. I am using mouse down and mouse up events for this. On Mouse down, I store the position and on mouse up, check the difference between positions and set...
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 non-negative and less than the size of the collection. Parameter name: index"" I have tried, -1,0,1,2 for the index, and I get the same error message on each try.
by: martin | last post by:
Hi, I have a datagrid that contains 3 colums. This is rendered to the page fine, except that I would like to be able to control the width of each table cell of the datagrid I have the following code in the "ItemDataBound" -- which I belive should allow me to alter the width of the cells, however it does not work. Dim unitWidth As Unit unitWidth.Percentage(10)
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 far everything is fine. Now i try to format the embedded datagrid - e.g. setting font size and the column size/width of each column. Everything is working fine, except the width of the columns.
by: Aziz | last post by:
1. I have a shopping basket DataGrid with a list of products. What I want to do is when the user clicks on a row, a button will become visible/be created that allows user to edit the quantity. The button will be dynamic and always show up on the same Y-axis position as the selected row. So, how do I get back the X, Y co-ordinates of a specific row in a datagrid relative to the form? 2. I managed to change individual column width using:
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 actually happens is... when the Text size is too big... the column
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...

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.