In This Topic
Identifiers are means to locate different objects in the DOM tree. There are several types of identifiers and each of them is responsible for locating a particular type of DOM object (element, attribute or atom).
All identifiers inherit from the
NIdentifier abstract class and are only valid in the context of the document in which the identified object resides. (i.e. if you add or remove elements from the document some identifiers may become invalid).
The following code snippets use Nevron Chart for .NET to illustrate how to work with identifiers, but the same code also applies to Nevron Diagram for .NET.
Element Identifiers
Element identifiers pinpoint DOM elements. Suppose that you have a label in the chart that you want to access via it?s id at a latter stage (for example after a postback). You may do so by using the following code:
C# |
Copy Code
|
// create and add a label to the chart document
NLabel label = new NLabel();
chartControl.Panels.Add(label);
NElementIdentifier elementIdentifier = new ElementIdentifier(label.Id);
// retrieve the label from the document
NLabel label1 = elementIdentifier.FindInDocument(chartControl.Document) as NLabel;
|
Visual Basic |
Copy Code
|
'create and add a label to the chart document
Dim label As New NLabel
chartControl.Panels.Add(label)
Dim elementIdentifier As New NElementIdentifier(label.Id)
'retrieve the label from the document
Dim label1 As NLabel = elementIdentifier.FindInDocument(chartControl.Document)
|
Element Atom Identifiers
In the context of Nevron DOM atoms are very small objects that may not exists in object form but still need to be treated as parts of the DOM tree. For example the data points in Nevron Chart for .NET are internally stored in tables and not as separate objects in order to decrease the amount of used memory. Furthermore maintaining reference integrity and document id (Id) is too expensive for these types of objects. Atoms can be identified by using the NElementAtomIdentifier:
C# |
Copy Code
|
// create a simple bar series and an identifier pinpointing the second atom (bar)
NChart chart = chartControl.Charts[0];
NBarSeries bar = (NBarSeries)chart.Series.Add(SeriesType.Bar);
bar.Values.Add(10);
bar.Values.Add(20);
bar.Values.Add(30);
NElementAtomIdentifier elementAtomIdentifier = new NElementAtomIdentifier(bar.Id, 1);
// retrieve the value of the second bar using the atom identifier
NDataPoint dataPoint = elementAtomIdentifier.FindInDocument(chartControl.Document) as NDataPoint;
double secondBarValue = (double)dataPoint[DataPointValue.Value];
|
Visual Basic |
Copy Code
|
'create a simple bar series and an identifier pinpointing the second atom (bar)
Dim chart As NChart = chartControl.Charts(0)
Dim bar As NBarSeries = chart.Series.Add(SeriesType.Bar)
bar.Values.Add(10)
bar.Values.Add(20)
bar.Values.Add(30)
Dim elementAtomIdentifier As New NElementAtomIdentifier(bar.Id, 1)
'retrieve the value of the second bar using the atom identifier
Dim dataPoint As NDataPoint = elementAtomIdentifier.FindInDocument(chartControl.Document)
Dim secondBarValue As Double = dataPoint(DataPointValue.Value)
|
Attribute Identifiers
Attributes are attached to DOM elements and do not have a document id because it is presumed that their relationship with the parent element is static ? for example a chart wall has one fill style and is not expected to have more. Creating an attribute identifier is similar to creating an element atom one:
C# |
Copy Code
|
// Create an element attribute identifier for the back chart wall fill style
NChart chart = chartControl.Charts[0];
NChartWall wall = chart.Wall(ChartWallType.Back);
NElementAttributeIdentifier elementAttributeIdentifer = new NElementAttributeIdentifier(wall.Id, "FillStyle");
// Retrieve the fill style of the chart back wall
NFillStyle backWallFillStyle = elementAttributeIdentifer.FindInDocument(chartControl.Document) as NFillStyle;
|
Visual Basic |
Copy Code
|
// Create an element attribute identifier for the back chart wall fill style
Dim chart As NCartesianChart = chartControl.Charts(0)
Dim wall As NChartWall = chart.Wall(ChartWallType.Back)
Dim elementAttributeIdentifer As New NElementAttributeIdentifier(wall.Id, "FillStyle")
// Retrieve the fill style of the chart back wall
Dim backWallFillStyle As NFillStyle = elementAttributeIdentifer.FindInDocument(chartControl.Document)
|
Common Identifiers Features
All identifiers support conversion to string and can be created from a string representation using the static FromString method of the NIdentifier base class:
C# |
Copy Code
|
NIdentifier someIdentifier = NIdentifier.FromString(someIdentifierString);
|
Visual Basic |
Copy Code
|
Dim someIdentifier As NIdentifier = NIdentifier.FromString(someIdentifierString)
|
See Also