| layout | post |
|---|---|
| title | Pivot Rows in Windows Forms Pivot Grid control | Syncfusion |
| description | Learn about Pivot Rows support in Syncfusion Windows Forms Pivot Grid control, its elements and more details. |
| platform | windowsforms |
| control | PivotGrid |
| documentation | ug |
Pivot rows are defined by using the PivotItem object which holds the information needed for rows that appear in the pivot grid control.
To define a pivot row item, the following properties of PivotItem object are used.
Refer to the below code sample for adding pivot row item in the pivot grid control.
{% tabs %}
{% highlight c# %}
// Defining pivot item PivotItem pivotItem = new PivotItem() { FieldHeader = "Product", FieldMappingName = "Product", TotalHeader = "Total" };
// Adding pivot row item to pivot grid this.pivotGridControl1.PivotRows.Add(pivotItem);
{% endhighlight %}
{% highlight vb %}
' Defining pivot item Dim pivotItem As New PivotItem() With {.FieldHeader = "Product", .FieldMappingName = "Product", .TotalHeader = "Total"}
' Adding pivot row item to pivot grid Me.pivotGridControl1.PivotRows.Add(pivotItem)
{% endhighlight %}
{% endtabs %}
To synchronize the newly added or modified pivot row items with the pivot grid control, the SynchronizePivotItems method will be used. This method will be invoked whenever the collection of pivot row items gets changed.
By default, the pivot grid control sorts the row data in ascending order. The sorting order can be changed by defining custom comparer and it needs to be assigned using the Comparer property of corresponding pivot item.
Refer to the below code sample to define comparer for sorting the row data in descending order.
{% tabs %}
{% highlight c# %}
public partial class Form1 : Form { public Form1() { ...... this.pivotGridControl1.PivotRows.Add(new PivotItem { FieldMappingName = "Product", Comparer = new ReverseOrderComparer() }); ...... } }
// Reverse order comparer for sorting the data in descending order public class ReverseOrderComparer : IComparer { public int Compare(object x, object y) { if (x == null && y == null) return 0; else if (y == null) return 1; else if (x == null) return -1; else return -x.ToString().CompareTo(y.ToString()); } }
{% endhighlight %}
{% highlight vb %}
Partial Public Class Form1 Inherits Form Public Sub New() ..... Me.pivotGridControl1.PivotRows.Add(New PivotItem With {.FieldMappingName = "Product", .Comparer = New ReverseOrderComparer()}) ..... End Sub End Class
' Reverse order comparer for sorting the data in descending order Public Class ReverseOrderComparer Inherits IComparer
Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer
If x Is Nothing AndAlso y Is Nothing Then
Return 0
ElseIf y Is Nothing Then
Return 1
ElseIf x Is Nothing Then
Return -1
Else
Return -x.ToString().CompareTo(y.ToString())
End If
End Function
End Class
{% endhighlight %}
{% endtabs %}
The height of the pivot rows can be changed using the QueryRowHeight event.
Refer the below code snippet to change the height of the pivot rows by using the row index.
{% tabs %}
{% highlight c# %}
pivotGridControl1.TableModel.QueryRowHeight += TableModel_QueryRowHeight;
private void TableModel_QueryRowHeight(object sender, Syncfusion.Windows.Forms.Grid.GridRowColSizeEventArgs e)
{
if (e.Index > 2)
{
e.Size = 16;
e.Handled = true;
}
}
{% endhighlight %}
{% highlight vb %}
AddHandler pivotGridControl1.TableModel.QueryRowHeight, AddressOf TableModel_QueryRowHeight
Private Sub TableModel_QueryRowHeight(ByVal sender As Object,ByVal e As GridRowColSizeEventArgs) If e.Index > 2 Then e.Size = 16 e.Handled = True End If End Sub
{% endhighlight %}
{% endtabs %}
