473,406 Members | 2,549 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,406 software developers and data experts.

Columns in a DataGrid do not respond

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
1 1118
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Billy Jacobs | last post by:
I am using a datagrid to display some data. I need to create 2 header rows for this grid with columns of varying spans. In html it would be the following. <Table> <tr> <td colspan=8>Official...
3
by: Diego TERCERO | last post by:
Hi... I'm working on a tool for editing text resources for a family of software product my company produces. These text resources are found in a SQL Server database, in a table called...
2
by: Kevin | last post by:
Hi Al Can someone tell me how to hide colums in a datagrid. I have a one datagrid that is a master and child and I would like to hide specific columns, how do I do this TI Kevin
1
by: Amber | last post by:
The DataGrid allows you to make columns visible or invisible on demand - even edit and other special columns. This article will show you how it is done. Some developers have reported problems...
1
by: J.B | last post by:
I have a datagrid that will display different datasets, (it runs different sprocs based on a value in the querystring) but it will always return 6 columns. The 5th and 6th columns are always Date...
6
by: John Ruiz | last post by:
Greetings, I originally posted this to microsoft.public.dotnet.framework.aspnet.datagridcontrol two weeks ago, but no one was able to answer. I am unable to dynamically add columns to a...
8
by: Hanson | last post by:
I have a datagrid control in an aspx page. The datagrid columns will be dynamically generated according to the pre-page's search condition, I want to hide some columns in the datagrid. is that...
2
by: CSL | last post by:
I am using the DataGrid in a Windows Application, how can I adjust the widths of each column individually.
0
by: tafpin | last post by:
I have an application with a datagrid. In the IDE I have 2 template columns. The first has an image button and the second contains a link button. According to the results that I get back I must...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.