473,795 Members | 2,826 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
advance.

regards,
hajash
Nov 16 '05 #1
2 1716
Hajash,

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

http://msdn.microsoft.com/library/de...widthtopic.asp

Be aware that this does not fix it.

I hope this helps,

Cor
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
width)

{
try

{
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
www.syltek.com
Hajash wrote:
hi all,

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

regards,
hajash


Nov 16 '05 #3

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

Similar topics

5
3380
by: Prateek | last post by:
Hi, How can I change the width of a column in datagrid control? TIA Prateek
1
1995
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...
9
3945
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,
0
1578
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...
24
10766
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.
1
2152
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)
1
2483
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.
3
4685
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:
2
10406
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
0
9672
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9519
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,...
0
10438
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, 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...
0
10001
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 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...
1
7540
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 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...
0
5437
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...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3727
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.