473,654 Members | 3,089 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

The width of columns of datagrid

Hello,

In Visual Studio .NET 2003,

How can I change the columns' width (at design or runtime) of datagrid ?

Thanks :)
Nov 19 '05 #1
5 2082
You can reach them at runtime on "ItemDataBo und" event. Then you can change
the width by adding the following code to that event;

e.Item.Cells[5].Attributes.Add ("width","100px ");

where Cells[5] refers to the colum that you change width of

"John M" wrote:
Hello,

In Visual Studio .NET 2003,

How can I change the columns' width (at design or runtime) of datagrid ?

Thanks :)

Nov 19 '05 #2
it's cells(0) (not cells[0])

I have tried this, but in vain :
I have three columns.
The event occurs three times :
2 with e.item.itemInde x = -1
1 with e.item.itemInde x = 0

I want to change once only, so what I did is :
If e.itam.itemInde x <> -1 then
e.cells(0).Attr ibutes.add("wid th", 50px')
e.cells(1).Attr ibutes.add("wid th", 50px')
e.cells(2).Attr ibutes.add("wid th", 50px')
end if

none of the columns was changed.

If I did the following :

If e.itam.itemInde x <> -1 then
e.cells(0).Attr ibutes.add("wid th", 50px')
end if

column 0 change it's width.

I think that the datagrid stay always with it's fixed width.

Any better ideas ?

Thanks :)
Nov 19 '05 #3
I haven't tried but you can solve this problem by not defining the width
property of the datagrid. On property box delete the width value. Define the
width of colums programmaticall y at runtime. I think this can solve the
problem, but again let me to say, i haven't tried that and i am not sure
whether this can work or not.

"John M" wrote:
it's cells(0) (not cells[0])

I have tried this, but in vain :
I have three columns.
The event occurs three times :
2 with e.item.itemInde x = -1
1 with e.item.itemInde x = 0

I want to change once only, so what I did is :
If e.itam.itemInde x <> -1 then
e.cells(0).Attr ibutes.add("wid th", 50px')
e.cells(1).Attr ibutes.add("wid th", 50px')
e.cells(2).Attr ibutes.add("wid th", 50px')
end if

none of the columns was changed.

If I did the following :

If e.itam.itemInde x <> -1 then
e.cells(0).Attr ibutes.add("wid th", 50px')
end if

column 0 change it's width.

I think that the datagrid stay always with it's fixed width.

Any better ideas ?

Thanks :)

Nov 19 '05 #4
Thanks, it works.

Another little problem that I see now after deleting the height & width is :
The handles of the datagrid (the little dots that I can drag them and
change due that the size of the datagrid).
are not the same size as the datagrid is on the screen.
And also the datagrid is right-aligned, but after I run the application, the
datagrid is left aligned.

(suppose the + are the handles)

On IDE :
+ +
+
//the
datagrid area */

When Running
+ +
+
//the datagrid area */

Columns inside the datagrid are right aligned,
but I cannot see why the datagrid is not alligned properly.

It's not a big problem, but it is a little annoying.

Any ideas ?

Thanks :)

"basulasz" <ba******@discu ssions.microsof t.com> wrote in message
news:CD******** *************** ***********@mic rosoft.com...
I haven't tried but you can solve this problem by not defining the width
property of the datagrid. On property box delete the width value. Define
the
width of colums programmaticall y at runtime. I think this can solve the
problem, but again let me to say, i haven't tried that and i am not sure
whether this can work or not.

"John M" wrote:
it's cells(0) (not cells[0])

I have tried this, but in vain :
I have three columns.
The event occurs three times :
2 with e.item.itemInde x = -1
1 with e.item.itemInde x = 0

I want to change once only, so what I did is :
If e.itam.itemInde x <> -1 then
e.cells(0).Attr ibutes.add("wid th", 50px')
e.cells(1).Attr ibutes.add("wid th", 50px')
e.cells(2).Attr ibutes.add("wid th", 50px')
end if

none of the columns was changed.

If I did the following :

If e.itam.itemInde x <> -1 then
e.cells(0).Attr ibutes.add("wid th", 50px')
end if

column 0 change it's width.

I think that the datagrid stay always with it's fixed width.

Any better ideas ?

Thanks :)

Nov 19 '05 #5
Solved... - ignore last message.
Datagrid was mistakenly right align.
(I still don't know why hanldes' width stayed wider then the actual
datagrid).

Thanks, anyway.

"John M" <nobody@nospam_ please.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Thanks, it works.

Another little problem that I see now after deleting the height & width is
:
The handles of the datagrid (the little dots that I can drag them and
change due that the size of the datagrid).
are not the same size as the datagrid is on the screen.
And also the datagrid is right-aligned, but after I run the application,
the datagrid is left aligned.

(suppose the + are the handles)

On IDE :
+ + +
//the
datagrid area */

When Running
+ + +
//the datagrid area */

Columns inside the datagrid are right aligned,
but I cannot see why the datagrid is not alligned properly.

It's not a big problem, but it is a little annoying.

Any ideas ?

Thanks :)

"basulasz" <ba******@discu ssions.microsof t.com> wrote in message
news:CD******** *************** ***********@mic rosoft.com...
I haven't tried but you can solve this problem by not defining the width
property of the datagrid. On property box delete the width value. Define
the
width of colums programmaticall y at runtime. I think this can solve the
problem, but again let me to say, i haven't tried that and i am not sure
whether this can work or not.

"John M" wrote:
it's cells(0) (not cells[0])

I have tried this, but in vain :
I have three columns.
The event occurs three times :
2 with e.item.itemInde x = -1
1 with e.item.itemInde x = 0

I want to change once only, so what I did is :
If e.itam.itemInde x <> -1 then
e.cells(0).Attr ibutes.add("wid th", 50px')
e.cells(1).Attr ibutes.add("wid th", 50px')
e.cells(2).Attr ibutes.add("wid th", 50px')
end if

none of the columns was changed.

If I did the following :

If e.itam.itemInde x <> -1 then
e.cells(0).Attr ibutes.add("wid th", 50px')
end if

column 0 change it's width.

I think that the datagrid stay always with it's fixed width.

Any better ideas ?

Thanks :)


Nov 19 '05 #6

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

Similar topics

5
3373
by: Prateek | last post by:
Hi, How can I change the width of a column in datagrid control? TIA Prateek
9
3940
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,
24
10750
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.
3
3539
by: Andre | last post by:
Hi, Did someone know why this code does'nt work (The TableCell Width). The cell don't have 600 and 150 like writed in width="600" and width="150". <asp:datagrid id="DataGrid1" runat="server" AutoGenerateColumns="false" ShowHeader="false" ShowFooter="false"> <Columns>
5
3632
by: VB Programmer | last post by:
I have a simple datagrid on a webform. (I'm using VB.NET.) In the page load I get some data, set the .DataSource property of the dg, then do a .DataBind. The columns are automatically created. Question: How can I dynamically change the width's of these columns? Thanks in advance.
1
2216
by: VB Programmer | last post by:
I have a datagrid which is bound to a datatable that I create on the fly. How do I set the width of each column via code? Ex: Column 1 is always 100, Column 2 is always 250, etc... Thanks!
0
1833
by: Reza Nabi | last post by:
Dear All: Banckgroud: I have a datagrid which lives inside a repeater. Which is working fine. What i need is to dyanamically set the column width of the grid (which lieves inside the repeater). Is there any way, we accomplish this? Any advice on this would be greatly appreciated. Reza. ---BEGIN PART Of ListApp.aspx --->
2
10392
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
3
6126
by: remya1000 | last post by:
I’m using Vb.net application program. I created a datagrid having text field and checkbox fields. Everything is displaying correctly. I have 9 Columns and each columns are equally separated. In DataGrid property, I made PreferredColumnWidth = 85. So its equally aligned. I would like to give more width for the column named Department than rest of the columns. Because when its equally aligned, I can see the Departments displayed. Department...
0
8379
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
8294
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
8816
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
8709
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 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...
1
8494
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,...
0
8596
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...
0
5627
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();...
1
2719
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
1597
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.