Formatting datagrids at run time

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • coleenholley

    Formatting datagrids at run time

    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.C olumns.Add(New DataColumn("Cou nty")) ... in the VB code and populate using

    ls_temp_arr = ls_temp.Substri ng(li_county_na me, li_county_name_ len).Trim(
    ls_county = ls_temp_arr.ToS tring().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/
  • Scott Allen

    #2
    Re: Formatting datagrids at run time

    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.DataFormatStr ing = ...
    c.SortExpressio n = ...
    ....
    DataGrid1.Colum ns.Add(c);

    HTH,

    --
    Scott



    On Thu, 29 Jan 2004 15:39:02 -0800, coleenholley wrote:
    [color=blue]
    >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.C olumns.Add(New DataColumn("Cou nty")) ... in the VB code and populate using:
    >
    >ls_temp_arr = ls_temp.Substri ng(li_county_na me, li_county_name_ len).Trim()
    >ls_county = ls_temp_arr.ToS tring().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/[/color]

    Comment

    • coleenholley

      #3
      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/

      Comment

      Working...