Glossary Item Box
xamDataPresenter's™ Initialize events are critical for accessing cell values as the control is being initialized. This is where you have access to each cell in a DataRecord, and can test its value, or set its value. For example, if you want to display some where on your Page/Window the total number of records with a certain value in them, you would need to enumerate over all the Records, and test the value of the cell, and the best place to do this is in the FieldLayoutInitialized event.
The following procedure assumes you have a data bound xamDataPresenter, and you want to enumerate over all the rows, to check to see how many records have a value of two in a specific field.. For more information, see Creating xamDataPresenter in XAML.
In XAML:
<igDP:XamDataPresenter x:Name="XamDataPresenter1"
...
FieldLayoutInitialized="XamDataPresenter1_FieldLayoutInitialized"/>
<igDP:XamDataPresenter.View>
<igDP:GridView/>
</igDP:XamDataPresenter.View>
</igDP:XamDataPresenter>
<igEditors:XamNumericEditor x:Name="XamNumericEditor1" ReadOnly="True" />
In Visual Basic:
Imports Infragistics.Windows.DataPresenter.Events
Imports Infragistics.Windows.DataPresenter
In C#:
using Infragistics.Windows.DataPresenter.Events;
using Infragistics.Windows.DataPresenter;
In Visual Basic:
Sub XamDataPresenter1_FieldLayoutInitialized(ByVal sender As Object, _
ByVal e As FieldLayoutInitializedEventArgs)
Dim counter As Integer = 0
Dim i As Integer
For i = 0 To Me.XamDataPresenter1.Records.Count - 1
' Check to see if the Record is a DataRecord
If TypeOf Me.XamDataPresenter1.Records(i) Is DataRecord Then
Dim myRecord As DataRecord = _
CType(Me.XamDataPresenter1.Records(i), DataRecord)
' Test the 3rd Field's Cell Value to see if it is a 2
If myRecord.Cells(2).Value.ToString() = "2" Then
' If it is we want to include it in our count
counter += 1
End If
End If
Next i
' Display the count
Me.XamNumericEditor1.Text = counter.ToString()
End Sub
In C#:
void XamDataPresenter1_FieldLayoutInitialized(object sender,
FieldLayoutInitializedEventArgs e)
{
int counter = 0;
for (int i = 0; i <= this.XamDataPresenter1.Records.Count-1; i++)
{
// Check to see if the Record is a DataRecord
if (this.XamDataPresenter1.Records[i] is DataRecord)
{
DataRecord myRecord =
(DataRecord)this.XamDataPresenter1.Records[i];
// Test the 3rd Field's Cell Value to see if it is a 2
if (myRecord.Cells[2].Value.ToString() == "2")
{
// If it is we want to include it in our count
counter++;
}
}
}
// Display the count
this.XamNumericEditor1.text = counter.ToString();
}
