The width of columns of datagrid

G

Guest

You can reach them at runtime on "ItemDataBound" 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
 
J

John M

Hello,

In Visual Studio .NET 2003,

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

Thanks :)
 
G

Guest

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 programmatically 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.
 
J

John M

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.itemIndex = -1
1 with e.item.itemIndex = 0

I want to change once only, so what I did is :
If e.itam.itemIndex <> -1 then
e.cells(0).Attributes.add("width", 50px')
e.cells(1).Attributes.add("width", 50px')
e.cells(2).Attributes.add("width", 50px')
end if

none of the columns was changed.

If I did the following :

If e.itam.itemIndex <> -1 then
e.cells(0).Attributes.add("width", 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 :)
 
J

John M

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 said:
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 programmatically 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 said:
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.itemIndex = -1
1 with e.item.itemIndex = 0

I want to change once only, so what I did is :
If e.itam.itemIndex <> -1 then
e.cells(0).Attributes.add("width", 50px')
e.cells(1).Attributes.add("width", 50px')
e.cells(2).Attributes.add("width", 50px')
end if

none of the columns was changed.

If I did the following :

If e.itam.itemIndex <> -1 then
e.cells(0).Attributes.add("width", 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 :)
 
J

John M

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 said:
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 said:
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 programmatically 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 said:
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.itemIndex = -1
1 with e.item.itemIndex = 0

I want to change once only, so what I did is :
If e.itam.itemIndex <> -1 then
e.cells(0).Attributes.add("width", 50px')
e.cells(1).Attributes.add("width", 50px')
e.cells(2).Attributes.add("width", 50px')
end if

none of the columns was changed.

If I did the following :

If e.itam.itemIndex <> -1 then
e.cells(0).Attributes.add("width", 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 :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top