A data series subset is a set of indexes and/or ranges of indexes. Each data series subset is represented by an instance of DataSeriesSubset class. Subsets are returned or required as arguments by various data manipulation functions.
The user can perform the following operations with subsets.
Adding Indexes and Ranges of Indexes
The user adds indexes or ranges of indexes in the subset with the AddIndex and AddRange methods. The following code adds indexes 3, 5, 6, 7, and 8 in a newly created subset.
VB.NET |
|
Dim subset As DataSeriesSubset = New DataSeriesSubset() subset.AddIndex(3) subset.AddRange(5, 8)
|
C# |
|
DataSeriesSubset subset = new DataSeriesSubset(); subset.AddIndex(3); subset.AddRange(5, 8);
|
Removing Indexes and Ranges of Indexes
The user can remove indexes from a subset with the RemoveIndex and RemoveRange methods. The following code will remove index 8 and all indexes in the 3 to 5 range. Thus the subset will contain indexes 6 and 7.
VB.NET |
|
subset.RemoveIndex(8) subset.RemoveRange(3, 5)
|
C# |
|
subset.RemoveIndex(8); subset.RemoveRange(3, 5);
|
Determining Whether an Index is Contained in a Subset
The user can query whether a specific index is contained in the subset with the Contains method. The first call in the following example will return true while the second call will fail.
VB.NET |
|
Dim bContains As Boolean bContains = subset.Contains(6) bContains = subset.Contains(3)
|
C# |
|
bool bContains; bContains = subset.Contains(6); bContains = subset.Contains(3);
|
Iterating the Indexes Contained in the Subset
The DataSeriesSubset class implements the IEnumerable interface. The following example enumerates all indexes in a subset:
VB.NET |
|
' enumerate using a foreach statement For Each index As Integer In subset ' do something for this index Next ' enumerate using the standard IEnumerable Dim it As IEnumerator = subset.GetEnumerator() While it.MoveNext() Dim index As Integer = CType(it.Current, Integer) ' do something for this index End While
|
C# |
|
// enumerate using a foreach statement foreach (int index in subset) { // do something for this index } // enumerate using the standard IEnumerable IEnumerator it = subset.GetEnumerator(); while (it.MoveNext()) { int index = (int)it.Current; // do something for this index }
|
Performing Set Operations with Other Subsets
The user can perform the following set operations with another subset:
- Combine (logical equivalent of OR)
The combine operation is performed with the Combine method. After the operation, the subset will contain all indexes specified in the current and paramSubset. For example:
VB.NET |
|
Dim paramSubset As DataSeriesSubset = New DataSeriesSubset() paramSubset.AddIndex(7) paramSubset.AddIndex(9) subset.Combine(paramSubset)
|
C# |
|
DataSeriesSubset paramSubset = new DataSeriesSubset(); paramSubset.AddIndex(7); paramSubset.AddIndex(9); subset.Combine(paramSubset);
|
Assuming that the subset originally contained 6 and 7, after the operation it will contain indexes 6, 7, and 9.
- Intersect (logical equivalent of AND)
The intersect operation is performed with the Intersect method. After the operation, the subset will contain only indexes that were contained in both subset and paramSubset. For example:
VB.NET |
|
subset.Clear() subset.AddRange(6, 7) subset.Intersect(paramSubset)
|
C# |
|
subset.Clear(); subset.AddRange(6, 7); subset.Intersect(paramSubset);
|
Assuming that paramSubset was not changed from the previous example, after this operation the subset will contain only index 7.
- Subtract
The subtract operation is performed by the Subtract method. After the operation, the subset will contain only the indexes that were contained in the subset and were not members of paramSubset. For example:
VB.NET |
|
subset.Clear() subset.AddRange(6, 7) subset.Subtract(paramSubset)
|
C# |
|
subset.Clear(); subset.AddRange(6, 7); subset.Subtract(paramSubset);
|
After the operation the subset will contain only index 6.
Extracting or Removing a Subset from a Single Data Series
The user can extract or remove the indexes contained in a data series subset from a data series. These operations are performed by the RemoveSubset and ExtractSubset methods of the DataSeries class. The RemoveSubset method removes the data items that are contained at the indexes specified in the subset. The ExtractSubset method will remove all items positioned on indexes not contained in the subset.
Extracting or Removing a Subset from Multiple Data Series
The RemoveSubset and ExtractSubset methods of the DataSeriesCollection class allow a subset to be removed or extracted from a set of aligned data series.
Related Examples
Windows Forms: Data Manipulation\General\Filtering; Data Manipulation\General\Evaluating
See Also
DataSeriesSubset | DataSeries | Filtering | Evaluating