The width of columns of datagrid

Discussion in 'ASP .Net' started by =?Utf-8?B?YmFzdWxhc3o=?=, May 11, 2005.

  1. 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

    "John M" wrote:

    > Hello,
    >
    > In Visual Studio .NET 2003,
    >
    > How can I change the columns' width (at design or runtime) of datagrid ?
    >
    > Thanks :)
    >
    >
    >
    =?Utf-8?B?YmFzdWxhc3o=?=, May 11, 2005
    #1
    1. Advertising

  2. =?Utf-8?B?YmFzdWxhc3o=?=

    John M Guest

    Hello,

    In Visual Studio .NET 2003,

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

    Thanks :)
    John M, May 11, 2005
    #2
    1. Advertising

  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 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" 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.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 :)
    >
    >
    >
    =?Utf-8?B?YmFzdWxhc3o=?=, May 11, 2005
    #3
  4. =?Utf-8?B?YmFzdWxhc3o=?=

    John M Guest

    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 :)
    John M, May 11, 2005
    #4
  5. =?Utf-8?B?YmFzdWxhc3o=?=

    John M Guest

    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" <> wrote in message
    news:...
    >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" 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.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 :)
    >>
    >>
    >>
    John M, May 11, 2005
    #5
  6. =?Utf-8?B?YmFzdWxhc3o=?=

    John M Guest

    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:%...
    > 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" <> wrote in message
    > news:...
    >>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" 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.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 :)
    >>>
    >>>
    >>>

    >
    >
    John M, May 11, 2005
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. AndrewF
    Replies:
    1
    Views:
    740
    Bruce Barker
    Oct 10, 2005
  2. kris
    Replies:
    11
    Views:
    859
  3. ssk
    Replies:
    5
    Views:
    5,458
    Jukka K. Korpela
    Oct 30, 2006
  4. rob thomson
    Replies:
    0
    Views:
    252
    rob thomson
    Sep 4, 2003
  5. ton
    Replies:
    2
    Views:
    200
    Alvin Bruney [MVP]
    Feb 11, 2004
Loading...

Share This Page