Problem with Datagrid Table Style

Hello: After studying many examples of datagrid table styles on this site and others; I've been working it  this week-end to try to change the format of my datagrid. When I use the following code; the datagrid shows up but has no sign of the new formatting.  I suspect my problem could be with this statement:         ts.MappingName = "ds_payment"  I would have thought that should be dbo_payments since that is the underlying table ; but when I change it to ts.mappingname="dbo_payments" ; I get an error.

Again. The grid works fine; its showing the data without any problem; its just unformated.

Thanks for any help you can provide.

Here is the current code:
--------------------------------------------------------------------------------------------------------------


Dim da_payment As New OleDb.OleDbDataAdapter("select [paymentid] as ID,[PaymentDate] as [Pmt Date], [Paymenttype] as [Pmt Method], [PaymentAmount] as Amt, document, expirationdate as [Exp Date]  from dbo_payments", sConnection)

Dim ds_payment As New DataSet
Dim cm_payment As CurrencyManager



        ' start formatting code

        Dim c As DataGridTextBoxColumn
        Dim ts As New DataGridTableStyle
        Dim ds As DataSet = New DataSet

        da_payment.Fill(ds_payment, "dbo_payments")
        gpayment.DataSource = ds_payment.Tables(0)
        gpayment.SetDataBinding(ds_payment, "dbo_payments")
        ts.MappingName = "ds_payment"




        c = New DataGridTextBoxColumn
        c.MappingName = "New ID"
        c.Width = 50
        c.HeaderText = "YYYYMM"
        c.Alignment = HorizontalAlignment.Left '(Right Or center)
        ts.GridColumnStyles.Add(c)

        c = New DataGridTextBoxColumn
        c.MappingName = "New Pmt Amt"
        c.Width = 50
        c.HeaderText = "Pmt Amt"
        ts.GridColumnStyles.Add(c)

        c = New DataGridTextBoxColumn
        c.MappingName = "New Name"
        c.Width = 200
        c.HeaderText = "Prod Name"
        ts.GridColumnStyles.Add(c)
        gpayment.TableStyles.Clear()
        gpayment.TableStyles.Add(ts)
sny23vpbAsked:
Who is Participating?
 
arif_eqbalCommented:
OK  lets try it


Dim da_payment As New OleDb.OleDbDataAdapter("select [paymentid] as ID,[PaymentDate] as [Pmt Date], [Paymenttype] as [Pmt Method], [PaymentAmount] as Amt, document, expirationdate as [Exp Date]  from dbo_payments", sConnection)

Dim ds_payment As New DataSet
Dim c As DataGridTextBoxColumn
        Dim ts As New DataGridTableStyle
        Dim ds As DataSet = New DataSet

        da_payment.Fill(ds_payment, "dbo_payments")
        gpayment.DataSource = ds_payment   '<--- Set Source as Dataset
        gpayment.DataMember =  "dbo_payments"   '<--- Member as the DataTable

        ts.MappingName = "dbo_payments"  '<--- Mapping name as DataTable not Dataset

        c = New DataGridTextBoxColumn
        c.MappingName = "ID"  '<-- The Column Name is ID, select [paymentid] as ID
        c.Width = 50
        c.HeaderText = "YYYYMM"
        c.Alignment = HorizontalAlignment.Left '(Right Or center)
        ts.GridColumnStyles.Add(c)

        c = New DataGridTextBoxColumn
        c.MappingName = "Amt"   '<-- Similarly the Query has column called Amt
        c.Width = 50
        c.HeaderText = "Pmt Amt"
        ts.GridColumnStyles.Add(c)

        c = New DataGridTextBoxColumn
        c.MappingName = "New Name"   '<---There's no Column in your Query called "New Name" So this Column would not show
        c.Width = 200
        c.HeaderText = "Prod Name"
        ts.GridColumnStyles.Add(c)
       
        gpayment.TableStyles.Add(ts)


that's it,
0
 
Bob LearnedCommented:
gpayment.DataSource = ds_payment.Tables(0)
ts.MappingName =  ds_payment.Tables(0).TableName

Bob
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.