Results 1 to 3 of 3

Thread: DataGrid column widths

  1. #1

    Thread Starter
    Fanatic Member Geespot's Avatar
    Join Date
    Oct 2001
    Location
    Birmingham, UK
    Posts
    577

    DataGrid column widths

    Hi

    Im having a bit of trouble with the DataGrid control.

    I have a Dataset that gets populated by the contents of an Access Database file.

    I then bind the DataGrid control to the dataset so the contents are displayed.

    Now im having trouble sizing the columns to fit the data that gets displayed there.

    I would like the columns to automatically resize themselfs to fit the data correctly. Current im using

    Code:
    .PreferredColumnWidth = 150
    but this makes the columns much to big for small fields, primary key for exmaple.

  2. #2
    Fanatic Member VBCrazyCoder's Avatar
    Join Date
    Apr 2003
    Posts
    681
    I think you need to add a custom table style to the datagrid. Try looking into this - sorry I don't have any code - just what I remember.

  3. #3
    New Member
    Join Date
    Jun 2003
    Posts
    4

    DataGrid column widths

    You can to use a TableStyle and add it to the DataGrid Tablestyles property.

    For example

    Dim dgStyle as DataGridTableStyle


    Dim dgTableStyle As New DataGridTableStyle()

    Me.DataGrid1.TableStyles.Clear()

    Dim colStyle1 As New DataGridTextBoxColumn()
    With colStyle1
    .Alignment = HorizontalAlignment.Left
    .HeaderText = "Name"
    .MappingName = "EmployeeName"
    .Width = 50
    End With
    dgTableStyle.GridColumnStyles.Add(colStyle1)

    ' This must be the table name or the format
    ' will not apply to the columns.
    dgTableStyle.MappingName = "tblEmployees"

    Me.DataGrid1.TableStyles.Add(dgTableStyle)
    "Convenience is not"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width