DataGrid Column Headers


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: DataGrid Column Headers

Hybrid View

  1. #1
    Greg Rothlander Guest

    DataGrid Column Headers


    Does anyone know an easy way to display the Description from a column in SQLServer
    as the column header in a DataGrid? Either that, or does anyone know how
    to modify the column header dynamically?

    I know how to directly code in the column heading, but I do not want to do
    this because I do not know what data will be placed in each column, until
    runtime. I could write some code that reads the column name and then assigns
    a string to the column header. The other option would be to pull the description
    out of SQL and simply use this as the column header. I would like to make
    this as dynamic as possible. I'm just not sure how to go about doing it!

    Any suggestions would be very much appreciated.

  2. #2
    Frank Oquendo Guest

    Re: DataGrid Column Headers

    Greg Rothlander wrote:

    > Any suggestions would be very much appreciated.


    Use the ItemDataBound event. It's fired for headers and footers as well
    as items. If the object passed is a header, populate the header's cells
    with the text you want.

    --
    There are 10 kinds of people. Those who understand binary and those who
    don't.

    http://code.acadx.com



  3. #3
    Greg Rothlander Guest

    Re: DataGrid Column Headers


    This seems to be what I want, but I'm not having any luck pulling out the
    current value of the header. Can you give me some items? I just need to
    take what is currently there (the default column names from SQL) and translate
    them using my own translation function, or it would be nice if I could somehow
    get SQL to use the column descriptions and not the column names to build
    my DataSet. Anyway, Here is basically what I want to do... of course this
    doesn't work because I can not read the currect header value.

    Any help or suggestions would be very much appreciated.

    Thanks,
    Greg


    private void DataGrid1_ItemDataBound(object s, DataGridItemEventArgs e)
    {
    if (e.Item.ItemType.ToString() == "Header")
    {
    e.Item.Cells[0].Text = GetFieldDesc(e.Item.Cells[0].Text);
    }
    }

    private string GetFieldDesc(string fieldName)
    {
    string[] strDesc = new string[] {"Last Name","First Name"};
    string[] strSQLColumn = new string[] {"LName","MName"};

    int theIndex = Array.IndexOf(strSQLColumn,fieldName);
    if(theIndex < 0)
    {
    return fieldName;
    }
    else
    {
    return strDesc[theIndex];
    }
    }

    "Frank Oquendo" <franko@acadx.com> wrote:
    >Greg Rothlander wrote:
    >
    >> Any suggestions would be very much appreciated.

    >
    >Use the ItemDataBound event. It's fired for headers and footers as well
    >as items. If the object passed is a header, populate the header's cells
    >with the text you want.
    >
    >--
    >There are 10 kinds of people. Those who understand binary and those who
    >don't.
    >
    >http://code.acadx.com
    >
    >



  4. #4
    mark wardell Guest

    Re: DataGrid Column Headers


    What we decided to do was Use Stored procedures we pas in conuntry code and
    Select XX , YY From Table As cXX, cYY
    I think you will find this approach preferable.
    "Greg Rothlander" <j.rothlander@att.net> wrote:
    >
    >This seems to be what I want, but I'm not having any luck pulling out the
    >current value of the header. Can you give me some items? I just need to
    >take what is currently there (the default column names from SQL) and translate
    >them using my own translation function, or it would be nice if I could somehow
    >get SQL to use the column descriptions and not the column names to build
    >my DataSet. Anyway, Here is basically what I want to do... of course this
    >doesn't work because I can not read the currect header value.
    >
    >Any help or suggestions would be very much appreciated.
    >
    >Thanks,
    >Greg
    >
    >
    >private void DataGrid1_ItemDataBound(object s, DataGridItemEventArgs e)
    >{
    > if (e.Item.ItemType.ToString() == "Header")
    > {
    > e.Item.Cells[0].Text = GetFieldDesc(e.Item.Cells[0].Text);
    > }
    >}
    >
    >private string GetFieldDesc(string fieldName)
    >{
    > string[] strDesc = new string[] {"Last Name","First Name"};
    > string[] strSQLColumn = new string[] {"LName","MName"};
    >
    > int theIndex = Array.IndexOf(strSQLColumn,fieldName);
    > if(theIndex < 0)
    > {
    > return fieldName;
    > }
    > else
    > {
    > return strDesc[theIndex];
    > }
    >}
    >
    >"Frank Oquendo" <franko@acadx.com> wrote:
    >>Greg Rothlander wrote:
    >>
    >>> Any suggestions would be very much appreciated.

    >>
    >>Use the ItemDataBound event. It's fired for headers and footers as well
    >>as items. If the object passed is a header, populate the header's cells
    >>with the text you want.
    >>
    >>--
    >>There are 10 kinds of people. Those who understand binary and those who
    >>don't.
    >>
    >>http://code.acadx.com
    >>
    >>

    >



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center