By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,282 Members | 1,587 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,282 IT Pros & Developers. It's quick & easy.

Columns in a DataGrid do not respond

P: n/a
I have a DataGrid connected to a DataSet (read in from an XML file). The
documentation that I've read suggests that I attach a DataGridTableStyle to
the DataGrid to allow for additional formatting. Each of the three columns
are text fields so I created and added DataGridTextBoxColumn to the
DataGridTableStyle. I set various properties of the DataGridTextBoxColumn
but none of them seem to affect the output. There is some type of
disconnect here and I don't see it. Can anyone help?

The code is listed below as well as the XML schema and XML data.

Code
*****************************

Imports System
Imports System.Data
Imports System.Xml
Imports System.Drawing
Imports System.Windows.Forms

Public Class TestDataGrid
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents dgTest As System.Windows.Forms.DataGrid
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.dgTest = New System.Windows.Forms.DataGrid()
CType(Me.dgTest,
System.ComponentModel.ISupportInitialize).BeginIni t()
Me.SuspendLayout()
'
'dgTest
'
Me.dgTest.CaptionVisible = False
Me.dgTest.DataMember = ""
Me.dgTest.HeaderForeColor = System.Drawing.SystemColors.ControlText
Me.dgTest.Location = New System.Drawing.Point(32, 32)
Me.dgTest.Name = "dgTest"
Me.dgTest.Size = New System.Drawing.Size(416, 216)
Me.dgTest.TabIndex = 0
'
'TestDataGrid
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(496, 317)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.dgTest})
Me.Name = "TestDataGrid"
Me.Text = "Test Data Grid"
CType(Me.dgTest, System.ComponentModel.ISupportInitialize).EndInit( )
Me.ResumeLayout(False)

End Sub

#End Region

Dim dsTM As DataSet
Dim mstrAppDataPath As String

Private Sub TestDataGrid_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim strStartupPath As String
Dim iLen As Integer

' get the application data path
strStartupPath = Application.StartupPath()
iLen = strStartupPath.LastIndexOf("\")
mstrAppDataPath = strStartupPath.Substring(0, iLen)

GetMappings()

End Sub

Private Sub GetMappings()

Dim ts As DataGridTableStyle
Dim cs As DataGridTextBoxColumn
Dim dtTM As DataTable

Dim sXMLDataFN As String

dsTM = New DataSet("SymbolMapping")

' Load the XML File

sXMLDataFN = mstrAppDataPath & "\data\SymbolMapping.xsd"
dsTM.ReadXmlSchema(sXMLDataFN)

sXMLDataFN = mstrAppDataPath & "\data\SymbolMapping.xml"
dsTM.ReadXml(sXMLDataFN)
dtTM = dsTM.Tables(0)

' this works but there is no way to change the
' width
'dtTM.Columns(0).ColumnName = "HQuote Name q"
'dtTM.Columns(1).ColumnName = "TC2000 Name q"
'dtTM.Columns(2).ColumnName = "Comment Name q"
'create a custom tablestyle and add three columnstyles
ts = New DataGridTableStyle()
ts.MappingName = "tsSymbolMapping"
' none of these settings seem to get displayed
' create a column for HQuote
cs = New DataGridTextBoxColumn()
cs.MappingName = "HQuote"
cs.HeaderText = "HQuote Symbol x"
cs.Width = 40
cs.NullText = ""
ts.GridColumnStyles.Add(cs)

' create a column for TC2000

cs = Nothing
cs = New DataGridTextBoxColumn()
cs.MappingName = "TC2000"
cs.HeaderText = "TC2000 Symbol x"
cs.Width = 40
cs.NullText = ""
ts.GridColumnStyles.Add(cs)

' create a column for Comment
cs = Nothing
cs = New DataGridTextBoxColumn()
cs.MappingName = "Comment"
cs.HeaderText = "Comment name x"
cs.Width = 160
cs.NullText = ""
ts.GridColumnStyles.Add(cs)

dgTest.TableStyles.Clear()
dgTest.TableStyles.Add(ts)
dgTest.CaptionVisible = False

dgTest.SetDataBinding(dsTM, dsTM.Tables(0).TableName)
ts = Nothing
cs = Nothing

End Sub

Private Sub dgTest_Navigate(ByVal sender As System.Object, ByVal ne As
System.Windows.Forms.NavigateEventArgs) Handles dgTest.Navigate

End Sub
End Class

XML Schema
*****************************

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://exactlymypoint.com/namespace"
xmlns="http://exactlymypoint.com/namespace"
xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xs:element name="Mappings">
<xs:annotation>
<xs:documentation>Maps HQuote symbols to TC2000
symbols</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence maxOccurs="unbounded">
<xs:element name="Map">
<xs:complexType>
<xs:sequence>
<xs:element name="HQuote"
type="xs:string"/>
<xs:element name="TC2000"
type="xs:string"/>
<xs:element name="Comment"
type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

XML
*****************************

<?xml version="1.0" encoding="UTF-8"?>
<Mappings xmlns="http://exactlymypoint.com/namespace"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://exactlymypoint.com/namespace
C:\DOCUME~1\sgould\MYDOCU~1\VISUAL~1\HourlyConvert er\HourlyConverter\data\Sy
mbolMapping.xsd">
<Map>
<HQuote>$INDU</HQuote>
<TC2000>dj-30</TC2000>
<Comment>Dow Jones Industrial Average (sm)</Comment>
</Map>
<Map>
<HQuote>DJI</HQuote>
<TC2000>dj-30</TC2000>
<Comment>Dow Jones Industrial Average (sm)</Comment>
</Map>
<Map>
<HQuote>TRAN</HQuote>
<TC2000>dj-20</TC2000>
<Comment>Dow Jones Transportation Average</Comment>
</Map>
<Map>
<HQuote>DJT</HQuote>
<TC2000>dj-20</TC2000>
<Comment>Dow Jones Transportation Average</Comment>
</Map>
<Map>
<HQuote>UTIL</HQuote>
<TC2000>dj-15</TC2000>
<Comment>Dow Jones Utilities Average</Comment>
</Map>
</Mappings>


Nov 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hi,

The mapping name for the tablestyle has be the same as the tables
name or it wont work. Try this.

ts.MappingName =dsTM.Tables(0).TableName

Ken
--------------
"Steve" <steve@i_dont_need_no_stinking_penis_pills.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
I have a DataGrid connected to a DataSet (read in from an XML file). The
documentation that I've read suggests that I attach a DataGridTableStyle to the DataGrid to allow for additional formatting. Each of the three columns are text fields so I created and added DataGridTextBoxColumn to the
DataGridTableStyle. I set various properties of the DataGridTextBoxColumn
but none of them seem to affect the output. There is some type of
disconnect here and I don't see it. Can anyone help?

The code is listed below as well as the XML schema and XML data.

Code
*****************************

Imports System
Imports System.Data
Imports System.Xml
Imports System.Drawing
Imports System.Windows.Forms

Public Class TestDataGrid
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents dgTest As System.Windows.Forms.DataGrid
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.dgTest = New System.Windows.Forms.DataGrid()
CType(Me.dgTest,
System.ComponentModel.ISupportInitialize).BeginIni t()
Me.SuspendLayout()
'
'dgTest
'
Me.dgTest.CaptionVisible = False
Me.dgTest.DataMember = ""
Me.dgTest.HeaderForeColor = System.Drawing.SystemColors.ControlText Me.dgTest.Location = New System.Drawing.Point(32, 32)
Me.dgTest.Name = "dgTest"
Me.dgTest.Size = New System.Drawing.Size(416, 216)
Me.dgTest.TabIndex = 0
'
'TestDataGrid
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(496, 317)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.dgTest}) Me.Name = "TestDataGrid"
Me.Text = "Test Data Grid"
CType(Me.dgTest, System.ComponentModel.ISupportInitialize).EndInit( ) Me.ResumeLayout(False)

End Sub

#End Region

Dim dsTM As DataSet
Dim mstrAppDataPath As String

Private Sub TestDataGrid_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim strStartupPath As String
Dim iLen As Integer

' get the application data path
strStartupPath = Application.StartupPath()
iLen = strStartupPath.LastIndexOf("\")
mstrAppDataPath = strStartupPath.Substring(0, iLen)

GetMappings()

End Sub

Private Sub GetMappings()

Dim ts As DataGridTableStyle
Dim cs As DataGridTextBoxColumn
Dim dtTM As DataTable

Dim sXMLDataFN As String

dsTM = New DataSet("SymbolMapping")

' Load the XML File

sXMLDataFN = mstrAppDataPath & "\data\SymbolMapping.xsd"
dsTM.ReadXmlSchema(sXMLDataFN)

sXMLDataFN = mstrAppDataPath & "\data\SymbolMapping.xml"
dsTM.ReadXml(sXMLDataFN)
dtTM = dsTM.Tables(0)

' this works but there is no way to change the
' width
'dtTM.Columns(0).ColumnName = "HQuote Name q"
'dtTM.Columns(1).ColumnName = "TC2000 Name q"
'dtTM.Columns(2).ColumnName = "Comment Name q"
'create a custom tablestyle and add three columnstyles
ts = New DataGridTableStyle()
ts.MappingName = "tsSymbolMapping"
' none of these settings seem to get displayed
' create a column for HQuote
cs = New DataGridTextBoxColumn()
cs.MappingName = "HQuote"
cs.HeaderText = "HQuote Symbol x"
cs.Width = 40
cs.NullText = ""
ts.GridColumnStyles.Add(cs)

' create a column for TC2000

cs = Nothing
cs = New DataGridTextBoxColumn()
cs.MappingName = "TC2000"
cs.HeaderText = "TC2000 Symbol x"
cs.Width = 40
cs.NullText = ""
ts.GridColumnStyles.Add(cs)

' create a column for Comment
cs = Nothing
cs = New DataGridTextBoxColumn()
cs.MappingName = "Comment"
cs.HeaderText = "Comment name x"
cs.Width = 160
cs.NullText = ""
ts.GridColumnStyles.Add(cs)

dgTest.TableStyles.Clear()
dgTest.TableStyles.Add(ts)
dgTest.CaptionVisible = False

dgTest.SetDataBinding(dsTM, dsTM.Tables(0).TableName)
ts = Nothing
cs = Nothing

End Sub

Private Sub dgTest_Navigate(ByVal sender As System.Object, ByVal ne As
System.Windows.Forms.NavigateEventArgs) Handles dgTest.Navigate

End Sub
End Class

XML Schema
*****************************

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://exactlymypoint.com/namespace"
xmlns="http://exactlymypoint.com/namespace"
xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xs:element name="Mappings">
<xs:annotation>
<xs:documentation>Maps HQuote symbols to TC2000
symbols</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence maxOccurs="unbounded">
<xs:element name="Map">
<xs:complexType>
<xs:sequence>
<xs:element name="HQuote"
type="xs:string"/>
<xs:element name="TC2000"
type="xs:string"/>
<xs:element name="Comment"
type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

XML
*****************************

<?xml version="1.0" encoding="UTF-8"?>
<Mappings xmlns="http://exactlymypoint.com/namespace"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://exactlymypoint.com/namespace
C:\DOCUME~1\sgould\MYDOCU~1\VISUAL~1\HourlyConvert er\HourlyConverter\data\Sy mbolMapping.xsd">
<Map>
<HQuote>$INDU</HQuote>
<TC2000>dj-30</TC2000>
<Comment>Dow Jones Industrial Average (sm)</Comment>
</Map>
<Map>
<HQuote>DJI</HQuote>
<TC2000>dj-30</TC2000>
<Comment>Dow Jones Industrial Average (sm)</Comment>
</Map>
<Map>
<HQuote>TRAN</HQuote>
<TC2000>dj-20</TC2000>
<Comment>Dow Jones Transportation Average</Comment>
</Map>
<Map>
<HQuote>DJT</HQuote>
<TC2000>dj-20</TC2000>
<Comment>Dow Jones Transportation Average</Comment>
</Map>
<Map>
<HQuote>UTIL</HQuote>
<TC2000>dj-15</TC2000>
<Comment>Dow Jones Utilities Average</Comment>
</Map>
</Mappings>

Nov 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.