473,396 Members | 1,792 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

My TableStyle Is Not Working

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
Nov 20 '05 #1
4 2663
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
------------------
"Ken Powers" <KP*****@wppisys.org> wrote in message
news:u4**************@TK2MSFTNGP12.phx.gbl...
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

Nov 20 '05 #2
Ken,

I did add my GridColumnStyles to my TableStyle.

dgtsAdj being my TablesStyle.

Anything else you can think of.

Ken
Nov 20 '05 #3
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("Cod e"))
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
Nov 20 '05 #4
Hi,

You can only bind a tablestyle to a table not a datareleation. If
you had a master and a detail grid on your form you could use a
datareleation to keep them in sync. Here is an link to an example.

http://msdn.microsoft.com/library/de...indowsForm.asp

Ken
------------------------------------------
"Ken Powers" <KP*****@wppisys.org> wrote in message
news:u4**************@TK2MSFTNGP12.phx.gbl...
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

Nov 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Herve MAILLARD | last post by:
I have added aTableStyle to my Datagrid. The table linked to the datagrid display a boolean field. Before apply the TableStyle,the datagrid was displaying a Checkbox. Since I have apply the...
2
by: tomp | last post by:
Hi, This is driving me crazy. Once the TableStyle is added (last line) the datagrid comes up blank. If I comment it out, the data grid shows the column names from the dataset. I must be doing...
1
by: Agnes | last post by:
For single datagrid, i can bind the table very well, I can add myGridTablestyle to the datagrid. However, after i set the relations before dgParents and dgDetails. It ignore my tablestyle()....
2
by: KC | last post by:
Why would the code below fail? I'm making a tablestyle, which works fine. I test to see if the style already exist for this datagrid, if it does, remove it before adding the new version. What I...
1
by: Bob | last post by:
is it possible to remove just a specific tablestyle and keep anyothers that may exist? I've got the folowing code: Dim TS As New DataGridTableStyle TS.MappingName = "ABQTG0UN" ...... ...
3
by: Reza G. | last post by:
I am creating a window forms, and placed a datagrid on it. Set the DataSource and DataMember, and I get all the column in the table (relation) shown. I used TableStyles of the DataGrid and add a...
2
by: Mac via DotNetMonster.com | last post by:
Hi all, I have a datagrid on a form which I have set the datasource (through the form designer) to be a dataset that I have added to the form, also through the form designer. I then have added a...
0
by: Kmistic | last post by:
I have created the datagrid in the following link http://support.microsoft.com/default.aspx?scid=kb;en-us;836672 When i try to apply a tablestyle i get an exeption stating that the data grid...
0
by: AliRezaGoogle | last post by:
Hi I have a problem with tablestyle of datagrid: First I create a new tablestyle in form designer. Then I add some gridecolumnstyle to the new tablestyle. I fill all MappingNames with correct...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.