DataGrid Column sizing - Help

Discussion in 'ASP .Net Datagrid Control' started by -Alex, Aug 30, 2004.

  1. -Alex

    -Alex Guest

    I have snipped the following code from an example only to find that it
    apparently doesn't work with regard to comlun sizing. I have been wrestling
    with this to no avail.

    The dataset is filled with the expected data but the size is wrong.
    Whenever I run with the code below numeric fields have a size of 1, vchar
    fields a size of 5 and date fields a size of 2.

    If I comment the column.width statements they all seem to default to about a
    size of 12.

    Can anyone twist my head in the right direction?

    Thanks,

    -Alex



    Private Sub Form1_Load(ByVal sender As System.Object, _

    ByVal e As System.EventArgs) Handles MyBase.Load

    Me.SqlDataAdapter1.Fill(Me.DataSet11)



    'Step 1: Create a DataGridTableStyle &

    ' set mappingname to table.

    Dim tableStyle As New DataGridTableStyle

    tableStyle.MappingName = "Clinics"

    'Step 2: Create DataGridColumnStyle for each col

    ' we want to see in the grid and in the

    ' order that we want to see them.



    'Step 2: ClinincID

    Dim column As New DataGridTextBoxColumn

    column.MappingName = "ClinicID"

    column.HeaderText = "Clinic ID"

    column.Width = 12

    tableStyle.GridColumnStyles.Add(column)

    'Step 2: ClinicName

    column = New DataGridTextBoxColumn

    column.MappingName = "ClinicName"

    column.HeaderText = "Clinic Name"

    column.Width = 30

    tableStyle.GridColumnStyles.Add(column)

    'Step 2: Administrator

    column = New DataGridTextBoxColumn

    column.MappingName = "Administrator"

    column.HeaderText = "Administrator"

    column.Width = 30

    tableStyle.GridColumnStyles.Add(column)

    'Step 2: ActivityCount

    column = New DataGridTextBoxColumn

    column.MappingName = "ActivityCount"

    column.HeaderText = "Activity Count"

    column.Width = 12

    tableStyle.GridColumnStyles.Add(column)

    'Step 2: LastActivityDateTime

    column = New DataGridTextBoxColumn

    column.MappingName = "LastActivityDateTime"

    column.HeaderText = "Last Activity"

    column.Width = 15

    tableStyle.GridColumnStyles.Add(column)

    'Step 3: Add the tablestyle to the datagrid

    Me.DataGrid1.TableStyles.Add(tableStyle)

    End Sub
     
    -Alex, Aug 30, 2004
    #1
    1. Advertising

  2. Alex,

    When it come to column width, the browser considers your instructions as
    recommendations only. It will make columns as wide as needed to accommodate
    the content. You can try to trick the browser by using non-breaking spaces,
    some other tricks, bust the best advice is to relax and put up with the
    browser's superiority.

    Eliyahu

    "-Alex" <> wrote in message
    news:1xMYc.4337$...
    > I have snipped the following code from an example only to find that it
    > apparently doesn't work with regard to comlun sizing. I have been

    wrestling
    > with this to no avail.
    >
    > The dataset is filled with the expected data but the size is wrong.
    > Whenever I run with the code below numeric fields have a size of 1, vchar
    > fields a size of 5 and date fields a size of 2.
    >
    > If I comment the column.width statements they all seem to default to about

    a
    > size of 12.
    >
    > Can anyone twist my head in the right direction?
    >
    > Thanks,
    >
    > -Alex
    >
    >
    >
    > Private Sub Form1_Load(ByVal sender As System.Object, _
    >
    > ByVal e As System.EventArgs) Handles MyBase.Load
    >
    > Me.SqlDataAdapter1.Fill(Me.DataSet11)
    >
    >
    >
    > 'Step 1: Create a DataGridTableStyle &
    >
    > ' set mappingname to table.
    >
    > Dim tableStyle As New DataGridTableStyle
    >
    > tableStyle.MappingName = "Clinics"
    >
    > 'Step 2: Create DataGridColumnStyle for each col
    >
    > ' we want to see in the grid and in the
    >
    > ' order that we want to see them.
    >
    >
    >
    > 'Step 2: ClinincID
    >
    > Dim column As New DataGridTextBoxColumn
    >
    > column.MappingName = "ClinicID"
    >
    > column.HeaderText = "Clinic ID"
    >
    > column.Width = 12
    >
    > tableStyle.GridColumnStyles.Add(column)
    >
    > 'Step 2: ClinicName
    >
    > column = New DataGridTextBoxColumn
    >
    > column.MappingName = "ClinicName"
    >
    > column.HeaderText = "Clinic Name"
    >
    > column.Width = 30
    >
    > tableStyle.GridColumnStyles.Add(column)
    >
    > 'Step 2: Administrator
    >
    > column = New DataGridTextBoxColumn
    >
    > column.MappingName = "Administrator"
    >
    > column.HeaderText = "Administrator"
    >
    > column.Width = 30
    >
    > tableStyle.GridColumnStyles.Add(column)
    >
    > 'Step 2: ActivityCount
    >
    > column = New DataGridTextBoxColumn
    >
    > column.MappingName = "ActivityCount"
    >
    > column.HeaderText = "Activity Count"
    >
    > column.Width = 12
    >
    > tableStyle.GridColumnStyles.Add(column)
    >
    > 'Step 2: LastActivityDateTime
    >
    > column = New DataGridTextBoxColumn
    >
    > column.MappingName = "LastActivityDateTime"
    >
    > column.HeaderText = "Last Activity"
    >
    > column.Width = 15
    >
    > tableStyle.GridColumnStyles.Add(column)
    >
    > 'Step 3: Add the tablestyle to the datagrid
    >
    > Me.DataGrid1.TableStyles.Add(tableStyle)
    >
    > End Sub
    >
    >
     
    Eliyahu Goldin, Aug 31, 2004
    #2
    1. Advertising

  3. Hi Alex,

    I have reviewed you post, and will reply you latter. Thanks for your
    understanding.

    Best regards,
    Jeffrey Tan
    Microsoft Online Partner Support
    Get Secure! - www.microsoft.com/security
    This posting is provided "as is" with no warranties and confers no rights.
     
    Jeffrey Tan[MSFT], Aug 31, 2004
    #3
  4. Hi Alex,

    Sorry for letting you wait for so long time.

    I think the problem should be that you did not specify the correct
    MappingName property for the DataGridTableStyle. You should set the
    DataGridTableStyle.MappingName to the datatable's tablename.

    The below code snippet works well:
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Load
    MakeParentTable()
    Me.DataGrid1.DataSource = myDataSet.Tables(0)

    Dim tableStyle As New DataGridTableStyle
    tableStyle.MappingName = "Clinics"
    Dim column As New DataGridTextBoxColumn
    column.MappingName = "id"
    column.HeaderText = "Clinic ID"
    column.Width = 50
    tableStyle.GridColumnStyles.Add(column)

    column = New DataGridTextBoxColumn
    column.MappingName = "Item"
    column.HeaderText = "Clinic Item"
    column.Width = 100
    tableStyle.GridColumnStyles.Add(column)
    tableStyle.MappingName = "MyTable"

    Me.DataGrid1.TableStyles.Add(tableStyle)
    End Sub

    Dim myDataSet As DataSet
    Private Sub MakeParentTable()
    ' Create a new DataTable.
    Dim myDataTable As DataTable = New DataTable("MyTable")
    ' Declare variables for DataColumn and DataRow objects.
    Dim myDataColumn As DataColumn
    Dim myDataRow As DataRow

    ' Create new DataColumn, set DataType, ColumnName and add to
    DataTable.
    myDataColumn = New DataColumn
    myDataColumn.DataType = System.Type.GetType("System.Int32")
    myDataColumn.ColumnName = "id"
    myDataColumn.ReadOnly = True
    myDataColumn.Unique = True
    ' Add the Column to the DataColumnCollection.
    myDataTable.Columns.Add(myDataColumn)

    ' Create second column.
    myDataColumn = New DataColumn
    myDataColumn.DataType = System.Type.GetType("System.String")
    myDataColumn.ColumnName = "Item"
    myDataColumn.AutoIncrement = False
    myDataColumn.Caption = "ParentItem"
    myDataColumn.ReadOnly = False
    myDataColumn.Unique = False
    ' Add the column to the table.
    myDataTable.Columns.Add(myDataColumn)

    ' Instantiate the DataSet variable.
    myDataSet = New DataSet
    ' Add the new DataTable to the DataSet.
    myDataSet.Tables.Add(myDataTable)

    ' Create three new DataRow objects and add them to the DataTable
    Dim i As Integer
    For i = 0 To 2
    myDataRow = myDataTable.NewRow()
    myDataRow("id") = i
    myDataRow("Item") = "Item " + i.ToString()
    myDataTable.Rows.Add(myDataRow)
    Next i
    End Sub

    ====================================
    Please apply my suggestion above and let me know if it helps resolve your
    problem.

    Thank you for your patience and cooperation. If you have any questions or
    concerns, please feel free to post it in the group. I am standing by to be
    of assistance.

    Best regards,
    Jeffrey Tan
    Microsoft Online Partner Support
    Get Secure! - www.microsoft.com/security
    This posting is provided "as is" with no warranties and confers no rights.
     
    Jeffrey Tan[MSFT], Sep 1, 2004
    #4
  5. Hi Alex,

    Is your problem resolved? Do you still have any concern on this issue?
    Please feel free to tell me. Thanks

    Best regards,
    Jeffrey Tan
    Microsoft Online Partner Support
    Get Secure! - www.microsoft.com/security
    This posting is provided "as is" with no warranties and confers no rights.
     
    Jeffrey Tan[MSFT], Sep 8, 2004
    #5
    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. =?Utf-8?B?TXJNaWtl?=

    Datagrid Sizing

    =?Utf-8?B?TXJNaWtl?=, Dec 27, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    1,830
    DM McGowan II
    Dec 29, 2004
  2. Replies:
    1
    Views:
    627
    Winista
    Jun 1, 2006
  3. Daniel Luis dos Santos

    JTable column sizing

    Daniel Luis dos Santos, Feb 10, 2010, in forum: Java
    Replies:
    1
    Views:
    765
    John B. Matthews
    Feb 10, 2010
  4. Mad Scientist Jr

    problem sizing columns in datagrid

    Mad Scientist Jr, Aug 13, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    3
    Views:
    165
    Mike Hutton
    Aug 24, 2004
  5. dew

    Datagrid & column sizing

    dew, Feb 23, 2006, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    154
    campwes
    Mar 8, 2006
Loading...

Share This Page