In message <7C**********************************@microsoft.co m>, Kerry
Moorman <Ke**********@discussions.microsoft.com> writes
Jeffrey,
Databinding won't work with public fields.
Instead of using public fields in the Person class, you need to use private
fields with public properties.
Kerry Moorman
Thanks. I did that and the DataGrid works now. The trouble is the Chart
won't take the DataGrid. I don't know why. The line
Chart1.ChartData = ReadingDataGrid gives a Bad Function argument. I take
it there is more to do with the DataGrid than just assigning it to
ChartData?
Public Class Form1
Inherits System.Windows.Forms.Form
Private number = 10
'Public myArray = New ArrayList
Public myCollection = New CollectionList
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Chart()
End Sub
Sub Chart()
Dim patient1 As New Patient
patient1.ReadingProperty = 1
patient1.ReadingValueProperty = 50
myCollection.add(patient1)
Dim patient2 As New Patient
patient2.ReadingProperty = 2
patient2.ReadingValueProperty = 60
myCollection.add(patient2)
ReadingDataGrid.SetDataBinding(myCollection.myArra y, "")
Chart1.ChartData = ReadingDataGrid
'Add a title and legend.
With Me.Chart1
.Title.Text = "Sales"
.Legend.Location.LocationType = _
MSChart20Lib.VtChLocationType.VtChLocationTypeBott om
.Legend.Location.Visible = True
End With
'Add titles to the axes.
With Me.Chart1.Plot
.Axis(MSChart20Lib.VtChAxisId.VtChAxisIdX).AxisTit le.Text =
"Year"
.Axis(MSChart20Lib.VtChAxisId.VtChAxisIdY).AxisTit le.Text =
"Millions of $"
End With
'Set custom colors for the bars.
With Me.Chart1.Plot
'Yellow for Company A
' -1 selects all the datapoints.
.SeriesCollection(1).DataPoints(-1).Brush.FillColor.Set(250,
250, 0)
'Purple for Company B
'.SeriesCollection(2).DataPoints(-1).Brush.FillColor.Set(200,
50, 200)
End With
End Sub
End Class
Public Class CollectionList
Public myArray As ArrayList
Public Sub New()
myArray = New ArrayList
End Sub
Public Sub Add(ByRef T As Patient)
myArray.Add(T)
End Sub
Public Sub Remove(ByRef T As Patient)
myArray.Remove(T)
End Sub
Public ReadOnly Property Count() As Integer
Get
Return myArray.Count
End Get
End Property
Public Function GetTrack(ByVal index As Integer) As Patient
Return myArray.Item(index)
End Function
End Class
Public Class Patient
Private Reading As Integer
Private ReadingValue As Integer
Public Property ReadingProperty() As Integer
Get
Return Reading
End Get
Set(ByVal Value As Integer)
Reading = Value
End Set
End Property
Public Property ReadingValueProperty() As Integer
Get
Return ReadingValue
End Get
Set(ByVal Value As Integer)
ReadingValue = Value
End Set
End Property
End Class
End Class
--
Jeffrey Spoon