Formatting datagrids at run time

Discussion in 'ASP .Net' started by coleenholley, Jan 29, 2004.

  1. coleenholley

    coleenholley Guest

    Hi all :-

    I have a datagrid which is populated from a class module (we have to do this because of the type connection we use -we DON'T use an SQL Server connection) the code populates the datatable at runtime. I need to specify column widths in the data grid in order to get the look & Feel correct for our users. I create the data column headers using

    dt_worksheet1.Columns.Add(New DataColumn("County")) ... in the VB code and populate using

    ls_temp_arr = ls_temp.Substring(li_county_name, li_county_name_len).Trim(
    ls_county = ls_temp_arr.ToString().Tri
    dr_gallons(0) = ls_count

    the problem is that some of the headers are longer and won't wrap correctly. I know that if I use bound datacolumns in the datagrid I can specify the column width, but because of the way we populate the datagrid, when I set the bound columns, the datagrid won't populate. Any way to do this programatically in the VB code behind? Thanks for any help/suggestions

    Coleen

    ---
    Posted using Wimdows.net NntpNews Component - Posted from .NET's Largest Community Website: http://www.dotnetjunkies.com/newsgroups/
    coleenholley, Jan 29, 2004
    #1
    1. Advertising

  2. coleenholley

    Scott Allen Guest

    Hi Coleen:

    You can programtically add bound columns to a DataGrid (see below).
    I'm assuming you are using ASP.NET since this is the ASP.NET
    newsgroup, but I'm not aware of a single, simple property you can set
    to control column width in the web forms datagrid.

    BoundColumn c = new BoundColumn()
    c.DataField = "DataField";
    c.DataFormatString = ...
    c.SortExpression = ...
    ....
    DataGrid1.Columns.Add(c);

    HTH,

    --
    Scott
    http://www.OdeToCode.com


    On Thu, 29 Jan 2004 15:39:02 -0800, coleenholley wrote:

    >Hi all :)
    >
    >I have a datagrid which is populated from a class module (we have to do this because of the type connection we use -we DON'T use an SQL Server connection) the code populates the datatable at runtime. I need to specify column widths in the data grid in order to get the look & Feel correct for our users. I create the data column headers using:
    >
    > dt_worksheet1.Columns.Add(New DataColumn("County")) ... in the VB code and populate using:
    >
    >ls_temp_arr = ls_temp.Substring(li_county_name, li_county_name_len).Trim()
    >ls_county = ls_temp_arr.ToString().Trim
    >dr_gallons(0) = ls_county
    >
    >
    >the problem is that some of the headers are longer and won't wrap correctly. I know that if I use bound datacolumns in the datagrid I can specify the column width, but because of the way we populate the datagrid, when I set the bound columns, the datagrid won't populate. Any way to do this programatically in the VB code behind? Thanks for any help/suggestions.
    >
    >Coleen
    >
    >---
    >Posted using Wimdows.net NntpNews Component - Posted from .NET's Largest Community Website: http://www.dotnetjunkies.com/newsgroups/
    Scott Allen, Jan 30, 2004
    #2
    1. Advertising

  3. coleenholley

    coleenholley Guest

    re: Re: Formatting datagrids at run time

    Thanks for your help Scott :-

    Yes, I'm using ASP.Net, with VB code-behind. I've got the columns all coming correctly using the VB Class module in the code-behind, but the column widhts are set to auto-generate at run-time. The problem with this is that in the datagrid properties, when I set it to auto-generate, the column widths do not generate how I want them to look. If I bind to the datacolumns, because of the way we connect to DB2 using an RPC from COBOL the data is not populated into the datagrid. I'm sure there has to be a way to do this...

    ---
    Posted using Wimdows.net NntpNews Component - Posted from .NET's Largest Community Website: http://www.dotnetjunkies.com/newsgroups/
    coleenholley, Jan 30, 2004
    #3
    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. Mike Fellows
    Replies:
    0
    Views:
    339
    Mike Fellows
    Mar 3, 2004
  2. mark
    Replies:
    2
    Views:
    450
  3. flamesrock
    Replies:
    8
    Views:
    434
    Hendrik van Rooyen
    Nov 24, 2006
  4. Pierre Yves
    Replies:
    2
    Views:
    470
    Pierre Yves
    Jan 10, 2008
  5. David Hearn
    Replies:
    1
    Views:
    403
    David Hearn
    Sep 10, 2003
Loading...

Share This Page