Multiple binding to DataGrid not working.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • tshad

    #1

    Multiple binding to DataGrid not working.

    On my VS 2003 Windows Forms page I am trying to reuse my DataTable dependant
    on the users preference. This is easy in Asp.net, but apparently not as
    easy here.

    If I do the following code, where I remove the Emails Table from the
    DataSet, it gives me an error at the line:

    EmailDataGrid.T ableStyles.Add( dgStyle)

    with the error:

    "The data grid table styles collection already contains a table style with
    the same mapping name.
    Parameter name: table"

    *************** *************** *************** ***
    Private Sub Loademails(ByVa l systemID As Integer)
    Dim da As New SqlDataAdapter( "GetEmailMessag es", dbConn)
    da.SelectComman d.CommandType = CommandType.Sto redProcedure
    Try
    If Not ds.Tables("Emai ls") Is Nothing Then
    ds.Tables.Remov e("Emails")
    da.Fill(ds, "Emails")
    Dim dgStyle As New DataGridTableSt yle
    dgStyle.Mapping Name = "Emails"
    Dim colStyle1 As New DataGridTextBox Column
    '
    ' Set column 1's caption, width and disable editing.
    '
    With colStyle1
    .MappingName = "date_queue d"
    .HeaderText = "Queued"
    .Width = 100
    .Alignment = HorizontalAlign ment.Left
    .TextBox.Enable d = True
    .Format = "yyyy-MM-dd hh:mm"
    End With


    ' Add the GridColumnStyle s to the DataGrid's Column Styles
    collection.
    '
    With dgStyle.GridCol umnStyles
    .Add(colStyle1)
    End With

    '
    ' Add the GridTableStyle to the DataGrid
    '
    EmailDataGrid.T ableStyles.Add( dgStyle)
    EmailDataGrid.D ataSource = ds.Tables("Emai ls")
    Catch ex As Exception
    Dim temp As String = ex.Message
    End Try
    End Sub
    *************** *************** *************** ************

    What to I need to do to keep binding a new table to the same DataGrid?

    Thanks,

    Tom



Working...