My TableStyle Is Not Working

K

Ken Powers

I have a bound datagrid that has data but the formatting from the TableStyle
is not affecting the appearence of the grid. Code below.

Private Sub BindDataGrid()
Try
dgActiveAdj.TableStyles.Clear()

dgtsAdj = New DataGridTableStyle
dgtsAdj.MappingName = "UTILITY.UtilToAdjust"

' This is a valid DataRelation of dsDataSet

With dgActiveAdj
.DataSource = dsDataSet
.DataMember = "UTILITY.UtilToAdjust"
.AllowSorting = True
End With

dgtsAdj.MappingName = "UTILITY.UtilToAdjust"

Dim grdColStyle1 As New DataGridTextBoxColumn
With grdColStyle1
.HeaderText = "Adjustment Name"
.MappingName = "UTILITY.UtilToAdjust.AdjustmentName"
dgtsAdj.GridColumnStyles.Add(grdColStyle1)
End With

grdColStyle1 = New DataGridTextBoxColumn
With grdColStyle1
.HeaderText = "Amount"
.MappingName = "UTILITY.UtilToAdjust.Adjustment"
dgtsAdj.GridColumnStyles.Add(grdColStyle1)
End With

grdColStyle1 = New DataGridTextBoxColumn
With grdColStyle1
.HeaderText = "Start Data"
.MappingName = "UTILITY.UtilToAdjust.AdjStartDate"
dgtsAdj.GridColumnStyles.Add(grdColStyle1)
End With

grdColStyle1 = New DataGridTextBoxColumn
With grdColStyle1
.HeaderText = "End Data"
.MappingName = "UTILITY.UtilToAdjust.AdjEndDate"
dgtsAdj.GridColumnStyles.Add(grdColStyle1)
End With

dgActiveAdj.TableStyles.Add(dgtsAdj)
dgActiveAdj.TableStyles(0).ReadOnly = True

Catch ex As Exception
MessageBox.Show(ex.Source.ToString & " - " & ex.Message,
Application.ProductName, _
MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try

End Sub
 
K

Ken Tucker

Hi,

Two things. 1 When filling the dataset specify the name. 2 you did
not add the gridcolumnstyles to the table style.

Here is an example of how to setup a grid.
Dim ts As New DataGridTableStyle

ts.MappingName = "InvoiceData"



Dim colDescription As New DataGridTextBoxColumn

With colDescription

..MappingName = "Description"

..HeaderText = "Description"

..Width = 280

..NullText = ""

End With

Dim colQty As New DataGridTextBoxColumn

With colQty

..MappingName = "Quantity"

..HeaderText = "Qty"

..Width = 50

End With

Dim cm As CurrencyManager = CType(Me.BindingContext(dvClient),
CurrencyManager)

Dim pd As System.ComponentModel.PropertyDescriptor =
cm.GetItemProperties()("Each")



Dim colEach As New DataGridTextBoxColumn(pd, "C")

With colEach

..MappingName = "Each"

..HeaderText = "Each"

..Width = 50

End With

Dim colPrice As New DataGridTextBoxColumn(pd, "C")

With colPrice

..MappingName = "Price"

..HeaderText = "Price"

..Width = 50

End With

ts.GridColumnStyles.Add(colDescription)

ts.GridColumnStyles.Add(colQty)

ts.GridColumnStyles.Add(colEach)

ts.GridColumnStyles.Add(colPrice)

dgInvoiceData.TableStyles.Add(ts)

ts = Nothing

colPrice = Nothing

colEach = Nothing

colQty = Nothing

colDescription = Nothing

Ken
------------------
 
K

Ken Powers

Ken,

I did add my GridColumnStyles to my TableStyle.

dgtsAdj being my TablesStyle.

Anything else you can think of.

Ken
 
K

Ken Powers

Ken,

To answer number 1 this is how I'm filling my DataSet. This sub fires
before I try ti bind to my DataGrid.

Private Sub Get_Data()
Try

Dim sqlcmd = New SqlCommand("select * from INPUT Order by CODE",
sqlConn)

daDataAdapter = New SqlDataAdapter
daDataAdapter.SelectCommand = sqlcmd

dsDataSet = New DataSet
daDataAdapter.Fill(dsDataSet, "INPUT")


sqlcmd = New SqlCommand("select * from Utility", sqlConn)
daDataAdapter = New SqlDataAdapter
daDataAdapter.SelectCommand = sqlcmd

daDataAdapter.Fill(dsDataSet, "Utility")

sqlcmd = New SqlCommand("select * from ratefil", sqlConn)
daDataAdapter = New SqlDataAdapter
daDataAdapter.SelectCommand = sqlcmd

daDataAdapter.Fill(dsDataSet, "ratefil")

sqlcmd = New SqlCommand("select * from ActiveAdjust", sqlConn)
daDataAdapter = New SqlDataAdapter
daDataAdapter.SelectCommand = sqlcmd

daDataAdapter.Fill(dsDataSet, "ActiveAdjust")

Dim dr As DataRelation = New _
DataRelation("UtilToInput",
dsDataSet.Tables("Utility").Columns.Item("code"),
dsDataSet.Tables("Input").Columns.Item("code"))
dsDataSet.Relations.Add(dr)
dr = New DataRelation("UtilToAdjust",
dsDataSet.Tables("Utility").Columns.Item("code"),
dsDataSet.Tables("ActiveAdjust").Columns.Item("Code"))
dsDataSet.Relations.Add(dr)

Set_Update_Command()

Catch ex As Exception
MessageBox.Show(ex.Source.ToString & " - " & ex.Message,
Application.ProductName, _
MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top