S
Steve
I would not have thought that getting a DataGrid connected to a DataSet
(read in from an XML file) would be this complicated. I cannot get this to
work. I have read everything I could find and modeled all the examples
given but this grid just refuses to behave nicely.
The code is listed below as well as the XML schema and XML data.
The connection between the data set and grid seems to work just fine. What
won't work is the display of the data. No matter what I do, the grid is
always displayed collapsed. I also do not want to display the "Mappings:"
caption that appears above the column headers. The column headers do not
seem to respond to the .width command.
I also read something about a SetDataBindings command that I do not know if
I need or not. Some code has it, some doesn't.
Any help would be, well, helpful.
Thanks.
Steve
***********************
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).BeginInit()
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)
GetTC2000Mappings()
BindXMLtoGrid()
End Sub
Private Sub GetTC2000Mappings()
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)
End Sub
Private Sub BindXMLtoGrid()
Dim ts As DataGridTableStyle
Dim cs As DataGridTextBoxColumn
dgTest.DataSource = dsTM
'create a custom tablestyle and add three columnstyles
ts = New DataGridTableStyle()
ts.MappingName = "tsSymbolMapping"
' create a column for TC2000
cs = New DataGridTextBoxColumn()
cs.MappingName = "TC2000"
cs.HeaderText = "TC2000 Symbol"
cs.Width = 40
cs.NullText = ""
ts.GridColumnStyles.Add(cs)
' create a column for HQuote
cs = Nothing
cs = New DataGridTextBoxColumn()
cs.MappingName = "HQuote"
cs.HeaderText = "HQuote Symbol"
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"
cs.Width = 160
cs.NullText = ""
ts.GridColumnStyles.Add(cs)
dgTest.TableStyles.Clear()
dgTest.TableStyles.Add(ts)
dgTest.CaptionVisible = False
ts = Nothing
cs = Nothing
End Sub
End Class
***********************
XML Schema in file AppDataPath & "\data\SymbolMapping.xsd"
<?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 Data in file AppDataPath & "\data\SymbolMapping.xsd"
<?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\HourlyConverter\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>
<Map>
<HQuote>DJU</HQuote>
<TC2000>dj-15</TC2000>
<Comment>Dow Jones Utilities Average</Comment>
</Map>
<Map>
<HQuote> DJX.X</HQuote>
<TC2000>dj-30</TC2000>
<Comment>Dow Jones Industrial Average (CBOE) </Comment>
</Map>
<Map>
<HQuote>DTX.X</HQuote>
<TC2000>dj-20</TC2000>
<Comment>Dow Jones Transportation Average (CBOE)</Comment>
</Map>
</Mappings>
(read in from an XML file) would be this complicated. I cannot get this to
work. I have read everything I could find and modeled all the examples
given but this grid just refuses to behave nicely.
The code is listed below as well as the XML schema and XML data.
The connection between the data set and grid seems to work just fine. What
won't work is the display of the data. No matter what I do, the grid is
always displayed collapsed. I also do not want to display the "Mappings:"
caption that appears above the column headers. The column headers do not
seem to respond to the .width command.
I also read something about a SetDataBindings command that I do not know if
I need or not. Some code has it, some doesn't.
Any help would be, well, helpful.
Thanks.
Steve
***********************
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).BeginInit()
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)
GetTC2000Mappings()
BindXMLtoGrid()
End Sub
Private Sub GetTC2000Mappings()
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)
End Sub
Private Sub BindXMLtoGrid()
Dim ts As DataGridTableStyle
Dim cs As DataGridTextBoxColumn
dgTest.DataSource = dsTM
'create a custom tablestyle and add three columnstyles
ts = New DataGridTableStyle()
ts.MappingName = "tsSymbolMapping"
' create a column for TC2000
cs = New DataGridTextBoxColumn()
cs.MappingName = "TC2000"
cs.HeaderText = "TC2000 Symbol"
cs.Width = 40
cs.NullText = ""
ts.GridColumnStyles.Add(cs)
' create a column for HQuote
cs = Nothing
cs = New DataGridTextBoxColumn()
cs.MappingName = "HQuote"
cs.HeaderText = "HQuote Symbol"
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"
cs.Width = 160
cs.NullText = ""
ts.GridColumnStyles.Add(cs)
dgTest.TableStyles.Clear()
dgTest.TableStyles.Add(ts)
dgTest.CaptionVisible = False
ts = Nothing
cs = Nothing
End Sub
End Class
***********************
XML Schema in file AppDataPath & "\data\SymbolMapping.xsd"
<?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 Data in file AppDataPath & "\data\SymbolMapping.xsd"
<?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\HourlyConverter\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>
<Map>
<HQuote>DJU</HQuote>
<TC2000>dj-15</TC2000>
<Comment>Dow Jones Utilities Average</Comment>
</Map>
<Map>
<HQuote> DJX.X</HQuote>
<TC2000>dj-30</TC2000>
<Comment>Dow Jones Industrial Average (CBOE) </Comment>
</Map>
<Map>
<HQuote>DTX.X</HQuote>
<TC2000>dj-20</TC2000>
<Comment>Dow Jones Transportation Average (CBOE)</Comment>
</Map>
</Mappings>