About Datagrid Columns

Discussion in 'MCSD' started by Kawabzi, Sep 22, 2003.

  1. Kawabzi

    Kawabzi Guest

    I'd like to know how to control the width of each
    DataGrid's column alone to be different from other columns.
    Note that my DataGrid is binded to a DataTable.
    Thanks
    Kawabzi, Sep 22, 2003
    #1
    1. Advertising

  2. Kawabzi

    Jay Walters Guest

    Check out Grid Styles...


    >-----Original Message-----
    >I'd like to know how to control the width of each
    >DataGrid's column alone to be different from other

    columns.
    >Note that my DataGrid is binded to a DataTable.
    > Thanks
    >
    >.
    >
    Jay Walters, Sep 24, 2003
    #2
    1. Advertising

  3. Kawabzi

    Rich Guest

    If you're talking about a Windows Control (as opposed to
    Web Control), you need to
    instantiate "DataGridTableStyle", which contains
    a "ColumnStyles" collection. You add members to the
    collection for each of the columns that should appear in
    your Grid. Once you've done that, you can manipulate
    quite a few properties in both DataGridTableStyles and
    the collection members for widths, fonts, colors,
    borders, etc.

    I hope this sample code will give you a basic model. It
    uses DataGridTextBoxColumn objects, which is the
    easiest. But you can derive your own classes to use as
    ColumnStyles, as well.

    Private Sub FillDocGrid(ByVal DocID As Integer)
    OleDbSelectCommand2.CommandText=SelectDocsCmd &
    DocID.ToString & "'"
    DocumentsDA.Fill(TechLibDS, "Documents")

    DocGrid.DataSource = TechLibDS
    DocGrid.DataMember = "Documents"
    Dim DocGridTS As New DataGridTableStyle()
    DocGridTS.RowHeadersVisible = False
    DocGridTS.MappingName = "TechLibDS.Documents"

    ' MappingName links DataTable columns to the
    ' ColumnStyles
    Dim IDCS As New DataGridTextBoxColumn()
    IDCS.MappingName = "ID"
    IDCS.HeaderText = ""
    IDCS.Width = 0
    DocGridTS.GridColumnStyles.Add(IDCS)

    Dim DocDateCS As New DataGridTextBoxColumn()
    DocDateCS.MappingName = "DocDate"
    DocDateCS.HeaderText = "Date"
    DocDateCS.Width = 120
    DocGridTS.GridColumnStyles.Add(DocDateCS)

    Dim TitleCS As New DataGridTextBoxColumn()
    TitleCS.MappingName = "Title"
    TitleCS.HeaderText = "Document Title"
    TitleCS.Width = 400
    DocGridTS.GridColumnStyles.Add(TitleCS)

    Dim DescCS As New DataGridTextBoxColumn()
    DescCS.MappingName = "Description"
    DescCS.HeaderText = "Document Descripition"
    DescCS.Width = 800
    DocGridTS.GridColumnStyles.Add(DescCS)

    DocGrid.TableStyles.Clear()
    DocGrid.TableStyles.Add(DocGridTS)
    End Sub

    HTH - there's more details in MSDN
    Rich



    >-----Original Message-----
    >I'd like to know how to control the width of each
    >DataGrid's column alone to be different from other
    >-----Original Message-----
    >I'd like to know how to control the width of each
    >DataGrid's column alone to be different from other

    columns.
    >Note that my DataGrid is binded to a DataTable.
    > Thanks
    >
    >.
    >
    Rich, Oct 3, 2003
    #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. Bookmark columns?

    , Feb 19, 2006, in forum: Firefox
    Replies:
    5
    Views:
    574
    Andy Luddy
    Feb 21, 2006
  2. ~¢makey$

    Is it possible to make multiple columns of tables?

    ~¢makey$, Nov 23, 2003, in forum: Computer Support
    Replies:
    2
    Views:
    542
    ~¢makey$
    Nov 23, 2003
  3. lbbss
    Replies:
    4
    Views:
    530
    gangle
    May 9, 2005
  4. =?Utf-8?B?UnVzc2VsbCBSZXdpcw==?=

    Lining up columns

    =?Utf-8?B?UnVzc2VsbCBSZXdpcw==?=, Nov 20, 2006, in forum: Microsoft Certification
    Replies:
    5
    Views:
    594
    Jonathan Roberts
    Nov 22, 2006
  5. Ron P

    Bookmark Width and columns

    Ron P, Dec 1, 2006, in forum: Firefox
    Replies:
    1
    Views:
    732
Loading...

Share This Page