Can't apply a DataGridTableStyle to a Datagrid

Hello,

I've this code:


    Private Sub BuildDgStyle()
        Dim dgStyle As New DataGridTableStyle
        dgStyle.MappingName = Me.Tabella

        Dim colCodice As New DataGridTextBoxColumn
        colCodice.HeaderText = Me.HeaderCodice
        colCodice.MappingName = Me.CampoCodice

        If Me.MaxCodLenght > Me.HeaderCodice.Length Then
            colCodice.Width = Me.MaxCodLenght + 5
        Else
            colCodice.Width = Me.HeaderCodice.Length + 5
        End If

        dgStyle.GridColumnStyles.Add(colCodice)

        Dim colDescrizione As New DataGridTextBoxColumn
        colDescrizione.HeaderText = Me.HeaderDescrizione
        colDescrizione.MappingName = Me.CampoDescrizione

        If Me.MaxDesLenght > Me.HeaderDescrizione.Length Then
            colDescrizione.Width = Me.MaxDesLenght + 5
        Else
            colDescrizione.Width = Me.HeaderDescrizione.Length + 5
        End If

        dgStyle.GridColumnStyles.Add(colDescrizione)

        Me.dgItems.TableStyles.Add(dgStyle)
    End Sub


And I call that sub from Form_Load. The problem is that vb doesn't apply the style to my grid.
Where's the error


Answer this question

Can't apply a DataGridTableStyle to a Datagrid

  • jesse_j3000

    What is Me.Tabella   What kind of data are you putting in the DataSource property
  • J. Aldrin

    Me.Tabella is a public property of my Form. It contains the name of the database table.
  • Filipe Madurera

    First I would make sure that the mapping name is getting passed to the tablestyle (go into debug and hover the mouse over it). 

    Then I would make sure you have your data set to the correct way.

    Datasource = dataset
    datamember = "tablename"

    Also, why are you doing this the hard way  you can do it via the designer alot better and faster. click the tablestyles property in the property browser and add a table style and then set the mapping then hit the grid column styles and then add your column styles.

    Easy as pie.

    Joe

  • Can't apply a DataGridTableStyle to a Datagrid