Page 1 of 1

using TYPEOF to determine series type

Posted: Wed Nov 08, 2006 6:21 am
by 9637403
I have been using typeof to determine series type i.e.

Code: Select all

 Dim ts As Steema.TeeChart.Styles.Series
  For Each ts In tc.Series
     If TypeOf (ts) Is Steema.TeeChart.Styles.Line Then
        ...
     end if

     If TypeOf (ts) Is Steema.TeeChart.Styles.Gantt Then 
        ...
     end if

     If TypeOf (ts) Is Steema.TeeChart.Styles.Points Then 
        ...
     end if
  next ts
this works fine for line and Points, however for some reason a GANTT series is of both GANTT and POINTS type.

Am I doing somethign completely stupid here or is there something else wrong?

Is there a better way to determine what type a series is?

Posted: Wed Nov 08, 2006 7:20 am
by Marjan
Hi.

Try using the is instead of typeof. Something like this:

Code: Select all

...
  if (ts is Steema.TeeChart.Styles.Line)
  { ... }
  else if (ts is Steema.TeeChart.Styles.Gantt
  { ... }
  else if (ts is Steema.TeeChart.Styles.Point)
  { ... }
...

Posted: Wed Nov 08, 2006 9:30 am
by 9637403
if I use

Code: Select all

 
If (ts Is Steema.TeeChart.Styles.Line) Then
   MsgBox("Line")
End If
I get a compile error "'Line' is a type is 'Styles' and cannot be used as an expression"

The Is operator determines if two object references refer to the same object. I want to know what type of object "ts" is

Posted: Wed Nov 08, 2006 9:36 am
by 9637403
A little more info:

The following code displays two message boxes, one for POINTS one for GANTT when ts is of type Steema.TeeChart.Styles.Gantt as determined by putting the mouse over ts in a debug session.

Code: Select all

If TypeOf ts Is Steema.TeeChart.Styles.Points Then
   MsgBox("Points")
End If

if TypeOf ts Is Steema.TeeChart.Styles.Gantt Then
   MsgBox("Gantt")
End If

Posted: Wed Nov 08, 2006 12:44 pm
by narcis
Hi Adrian,

This is because Gantt series inherit form Points series. However you can do it using:

Code: Select all

		Dim ts As Steema.TeeChart.Styles.Series

		For Each ts In TChart1.Series

			If TypeOf ts Is Steema.TeeChart.Styles.Line Then
				MsgBox("Line" + TChart1.Series.IndexOf(ts).ToString())
			End If

			If ts.GetType().Equals(GetType(Steema.TeeChart.Styles.Gantt)) Then
				MsgBox("Gantt" + TChart1.Series.IndexOf(ts).ToString())
			End If

			If TypeOf ts Is Steema.TeeChart.Styles.Points Then
				MsgBox("Points" + TChart1.Series.IndexOf(ts).ToString())
			End If
		Next ts