using TYPEOF to determine series type

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Adrian
Advanced
Posts: 116
Joined: Thu Jun 23, 2005 4:00 am

using TYPEOF to determine series type

Post by Adrian » Wed Nov 08, 2006 6:21 am

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?

Marjan
Site Admin
Site Admin
Posts: 745
Joined: Fri Nov 07, 2003 5:00 am
Location: Slovenia
Contact:

Post by Marjan » Wed Nov 08, 2006 7:20 am

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)
  { ... }
...
Marjan Slatinek,
http://www.steema.com

Adrian
Advanced
Posts: 116
Joined: Thu Jun 23, 2005 4:00 am

Post by Adrian » Wed Nov 08, 2006 9:30 am

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

Adrian
Advanced
Posts: 116
Joined: Thu Jun 23, 2005 4:00 am

Post by Adrian » Wed Nov 08, 2006 9:36 am

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

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Wed Nov 08, 2006 12:44 pm

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
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply