Set columns width in a datagrid using Compact Framework

前端 未结 3 409
梦毁少年i
梦毁少年i 2020-12-29 14:02

I\'m trying to set the width of the columns in my datagrid. I use Compact Framework 2.0 and C#

I tried this but it gives me an \"out of bonds\" error message:

<
3条回答
  •  温柔的废话
    2020-12-29 14:33

    I spent a better part of 2 days looking for the answer above. Thanks for the great solutions provided. Here is some vb code, with a customization of column widths by column:

        ' trgAppt is defined as system.windows.forms.datagrid
        trgAppt.TableStyles.Clear()
        Dim tableStyle As DataGridTableStyle
        tableStyle = New DataGridTableStyle
        tableStyle.MappingName = dtAppt.TableName
       For Each myItem As DataColumn In dtAppt.Columns
        Dim tbcName As DataGridTextBoxColumn = New DataGridTextBoxColumn
        Select Case myItem.ColumnName.ToString.ToUpper
         Case "STOP"
           tbcName.Width = 35
         Case "ORDER"
           tbcName.Width = 45
         Case "CUSTOMER"
           tbcName.Width = 70
         Case "QTY"
           tbcName.Width = 35
        End Select
        tbcName.MappingName = myItem.ColumnName
        tbcName.HeaderText = myItem.ColumnName
        tableStyle.GridColumnStyles.Add(tbcName)
        tbcName = Nothing
       Next
        trgAppt.TableStyles.Add(tableStyle)
        trgAppt.DataSource = dtAppt
    

提交回复
热议问题