VIBlend
Home Products Downloads Purchase Support Forum About Blog

Filter Silverlight DataGrid data programmatically

by viblend 10. July 2012 16:22
In order to achieve this, you need to follow the steps below:
 
1. Create DataGrid’s Rows, Columns and fill it with sample data. 
 
C#

for (int i = 0; i < 20; i++)
{
    this.dataGrid1.ColumnsHierarchy.Items.Add("Column " + i);
    this.dataGrid1.RowsHierarchy.Items.Add("Row " + i);
}

this.dataGrid1.AllowContextMenuFiltering = true;
this.dataGrid1.AllowContextMenuSorting = true;
Random random = new Random();

for (int i = 0; i < 20; i++)
{
    HierarchyItem row = this.dataGrid1.RowsHierarchy.Items[i];
    for (int j = 0; j < 20; j++)
    {
        HierarchyItem column = this.dataGrid1.ColumnsHierarchy.Items[j];
        column.AllowFiltering = true;
        this.dataGrid1.CellsArea.SetCellValue(row, column, (double)i);
    }
}

this.dataGrid1.ColumnsHierarchy.AutoResize(AutoResizeMode.FIT_ALL);
this.dataGrid1.RowsHierarchy.AutoResize(AutoResizeMode.FIT_ALL);

VB .NET

For i As Integer = 0 To 19
    Me.dataGrid1.ColumnsHierarchy.Items.Add("Column " & i)
    Me.dataGrid1.RowsHierarchy.Items.Add("Row " & i)
Next i

Me.dataGrid1.AllowContextMenuFiltering = True
Me.dataGrid1.AllowContextMenuSorting = True
Dim random As New Random()

For i As Integer = 0 To 19
    Dim row As HierarchyItem = Me.dataGrid1.RowsHierarchy.Items(i)
    For j As Integer = 0 To 19
        Dim column As HierarchyItem = Me.dataGrid1.ColumnsHierarchy.Items(j)
        column.AllowFiltering = True
        Me.dataGrid1.CellsArea.SetCellValue(row, column, CDbl(i))
    Next j
Next i

Me.dataGrid1.ColumnsHierarchy.AutoResize(AutoResizeMode.FIT_ALL)
Me.dataGrid1.RowsHierarchy.AutoResize(AutoResizeMode.FIT_ALL)
 
2. Create a new NumericFilter and set its ComparisonOperator and Value properties
 
C#

NumericFilter filter = new NumericFilter();
filter.ComparisonOperator = NumericComparisonOperator.GREATER_THAN;
filter.Value = 5;
FilterGroup<double?> filterGroup = new FilterGroup<double?>();
filterGroup.AddFilter(FilterOperator.AND, filter);

VB .NET

Dim filter As New NumericFilter()
filter.ComparisonOperator = NumericComparisonOperator.GREATER_THAN
filter.Value = 5
Dim filterGroup As FilterGroup(Of Nullable(Of Double)) = New FilterGroup(Of Nullable(Of Double))()
filterGroup.AddFilter(FilterOperator.AND, filter)

3. Create a new HierarchyItemFilter object and add the FilterGroup to it. 
 
C#

HierarchyItemFilter itemFilter = new HierarchyItemFilter();
itemFilter.Item = this.dataGrid1.ColumnsHierarchy.Items[0];
itemFilter.Filter = filterGroup;

VB .NET

Dim itemFilter As New HierarchyItemFilter()
itemFilter.Item = Me.dataGrid1.ColumnsHierarchy.
itemFilter.Filter = filterGroup
 
4. Finally, add the HierarchyItemFilter instance to the Filters collection of the DataGrid’s RowsHierarchy. 
 
C#

this.dataGrid1.RowsHierarchy.Filters.Add(itemFilter);

VB .NET

Me.dataGrid1.RowsHierarchy.Filters.Add(itemFilter)
 

Format DataGridView Cells

by viblend 7. June 2012 17:32
In this post, we will demonstrate you how to format the Cells in the VIBlend DataGridView for WinForms.

To achieve this, follow these steps:  

1.Create a new instance of the vDataGridView via drag and drop from the toolbox or create it programmatically.  
2.Bind the DataGrid to the Northwind Invoices table( Nwind.mdb is included in the download of the VIBlend Controls for WinForms package).  
 
C#

NwindDataSetTableAdapters.InvoicesTableAdapter adapter = new DataBindingAndEditors.NwindDataSetTableAdapters.InvoicesTableAdapter();
adapter.Fill(nwindDataSet1.Invoices);

DataTable tbl = this.nwindDataSet1.Invoices;

vDataGridView1.BoundFields.Clear();
vDataGridView1.BoundPivotColumns.Clear();
vDataGridView1.BoundPivotRows.Clear();
vDataGridView1.BoundPivotValues.Clear();
vDataGridView1.DataSource = null;

for (int i = 0; i < tbl.Columns.Count; i++)
{
    DataColumn col = tbl.Columns[i];
    BoundField boundField = new BoundField(col.Caption, col.ColumnName);
    vDataGridView1.BoundFields.Add(boundField);
}

vDataGridView1.DataSource = tbl;

vDataGridView1.ColumnsHierarchy.AutoResize();
vDataGridView1.RowsHierarchy.AutoResize();
vDataGridView1.Refresh();

VB .NET

Dim adapter As NwindDataSetTableAdapters.InvoicesTableAdapter = New DataBindingAndEditors.NwindDataSetTableAdapters.InvoicesTableAdapter()
adapter.Fill(nwindDataSet1.Invoices)

Dim tbl As DataTable = Me.nwindDataSet1.Invoices

vDataGridView1.BoundFields.Clear()
vDataGridView1.BoundPivotColumns.Clear()
vDataGridView1.BoundPivotRows.Clear()
vDataGridView1.BoundPivotValues.Clear()
vDataGridView1.DataSource = Nothing

Dim i As Integer = 0

Do While i < tbl.Columns.Count
    Dim col As DataColumn = tbl.Columns(i)
    Dim boundField As BoundField = New BoundField(col.Caption, col.ColumnName)
    vDataGridView1.BoundFields.Add(boundField)
    i += 1
Loop

vDataGridView1.DataSource = tbl

vDataGridView1.ColumnsHierarchy.AutoResize()
vDataGridView1.RowsHierarchy.AutoResize()
vDataGridView1.Refresh()

3. Set a custom format string to an entire grid column. 
 
C#

int columnIndex = this.nwindDataSet1.Invoices.Columns.IndexOf(this.nwindDataSet1.Invoices.RequiredDateColumn);
vDataGridView1.ColumnsHierarchy.Items[columnIndex].CellsFormatString = "{0:yyyy/MMMM/dd}";

VB .NET 

Dim columnIndex As Integer = Me.nwindDataSet1.Invoices.Columns.IndexOf(Me.nwindDataSet1.Invoices.RequiredDateColumn)
vDataGridView1.ColumnsHierarchy.Items(columnIndex).CellsFormatString = "{0:yyyy/MMMM/dd}"

 

VIBlend Silverlight Controls 6.0 With New Metro UI Themes

by viblend 18. January 2012 16:47

We are happy to announce the availability of VIBlend Silverlight Controls 6.0.  The newest version of VIBlend Silverlight Controls includes a set of new Metro UI Themes - Metro Blue, Metro Green and Metro Orange themes.

To download an evaluation version, please visit our Download page. 

View the updated Online Demo.

 

WinForms Grid with Merged Cells

by viblend 4. January 2012 01:06
In this post, we will show you how to use the cells merge functionality of VIBlend DataGridView for WinForms.

The first step is to add the DataGridView to your Form. You can do this by drag and drop from the Visual Studio toolbox or you can create it in the code behind.

C#

private vDataGridView grid = new vDataGridView();

public Form1()
{
    InitializeComponent();
    grid.Dock = DockStyle.Fill;
    grid.VIBlendTheme = VIBLEND_THEME.NERO;
    this.Controls.Add(grid);
    this.LoadData();
    this.MergeCells();
    this.SetCellsValues();
}

VB .NET

Private grid As New vDataGridView()

Public Sub New()
    InitializeComponent()
    grid.Dock = DockStyle.Fill
    grid.VIBlendTheme = VIBLEND_THEME.NERO
    Me.Controls.Add(grid)
    Me.LoadData()
    Me.MergeCells()
    Me.SetCellsValues()
End Sub

Now, we need to implement the LoadData, MergeCells and SetCellValues methods. The LoadData method will add rows and columns to the DataGridView.

C#

private void LoadData()
{
    // add columns.
    for (int i = 1; i <= 8; i++)
    {
        grid.ColumnsHierarchy.Items.Add("Column " + i);
    }
    // add rows.
    for (int i = 1; i <= 25; i++)
    {
        grid.RowsHierarchy.Items.Add("Row " + i);
    }

    grid.RowsHierarchy.AutoResize();
    grid.ColumnsHierarchy.AutoResize();
    grid.Refresh();
}

VB .NET

Private Sub LoadData()
    ' add columns.
    For i As Integer = 1 To 8
        grid.ColumnsHierarchy.Items.Add("Column " & i)
    Next i
    ' add rows.
    For i As Integer = 1 To 25
        grid.RowsHierarchy.Items.Add("Row " & i)
    Next i

    grid.RowsHierarchy.AutoResize()
    grid.ColumnsHierarchy.AutoResize()
    grid.Refresh()
End Sub

To add rows and columns we use the Add method of the DataGridView's Rows and Columns hierarchies.

The SetCellValues method will simply insert values in the Grid cells. This will be achieved by using the SetCellValue method which accepts three parameters - row, column and cell value.

C#

private void SetCellsValues()
{
    HierarchyItem rowItem1 = grid.RowsHierarchy.Items[0];
    HierarchyItem columnItem1 = grid.ColumnsHierarchy.Items[0];

    grid.CellsArea.SetCellValue(rowItem1, columnItem1, "Monthly Housing and Transportation Expenses");
    grid.CellsArea.SetCellValue(grid.RowsHierarchy.Items[1], columnItem1, "Primary residence");
    grid.CellsArea.SetCellValue(grid.RowsHierarchy.Items[1], this.grid.ColumnsHierarchy.Items[3], "Transportation Expenses");
    // fill data

    grid.CellsArea.SetCellValue(this.grid.RowsHierarchy.Items[2], columnItem1, "Mortgage Payment");
    grid.CellsArea.SetCellValue(this.grid.RowsHierarchy.Items[3], columnItem1, "Property Tax");
    grid.CellsArea.SetCellValue(this.grid.RowsHierarchy.Items[4], columnItem1, "Insurance");
    grid.CellsArea.SetCellValue(this.grid.RowsHierarchy.Items[5], columnItem1, "Electricity");
    grid.CellsArea.SetCellValue(this.grid.RowsHierarchy.Items[6], columnItem1, "Water");
    grid.CellsArea.SetCellValue(this.grid.RowsHierarchy.Items[7], columnItem1, "Cabel TV Service");
    grid.CellsArea.SetCellValue(this.grid.RowsHierarchy.Items[8], columnItem1, "High Speed Internet");

    // fill second column data.
    HierarchyItem columnItem2 = this.grid.ColumnsHierarchy.Items[1];
    grid.CellsArea.SetCellValue(this.grid.RowsHierarchy.Items[2], columnItem2, "$1,459,76");
    grid.CellsArea.SetCellValue(this.grid.RowsHierarchy.Items[3], columnItem2, "$212.54");
    grid.CellsArea.SetCellValue(this.grid.RowsHierarchy.Items[4], columnItem2, "$49.21");
    grid.CellsArea.SetCellValue(this.grid.RowsHierarchy.Items[5], columnItem2, "$73.44");
    grid.CellsArea.SetCellValue(this.grid.RowsHierarchy.Items[6], columnItem2, "$41.48");
    grid.CellsArea.SetCellValue(this.grid.RowsHierarchy.Items[7], columnItem2, "$22.14");
    grid.CellsArea.SetCellValue(this.grid.RowsHierarchy.Items[8], columnItem2, "$24.99");

    // fill third column data.

    HierarchyItem columnItem3 = this.grid.ColumnsHierarchy.Items[3];
    grid.CellsArea.SetCellValue(this.grid.RowsHierarchy.Items[2], columnItem3, "Vehicle 1 Payment");
    grid.CellsArea.SetCellValue(this.grid.RowsHierarchy.Items[3], columnItem3, "Vehicle 1 Insurance");
    grid.CellsArea.SetCellValue(this.grid.RowsHierarchy.Items[4], columnItem3, "Vehicle 1 Gas");
    grid.CellsArea.SetCellValue(this.grid.RowsHierarchy.Items[5], columnItem3, "Vehicle 1 Maintenance");
    grid.CellsArea.SetCellValue(this.grid.RowsHierarchy.Items[6], columnItem3, "Vehicle 2 Lease");
    grid.CellsArea.SetCellValue(this.grid.RowsHierarchy.Items[7], columnItem3, "Vehicle 2 Insurance");
    grid.CellsArea.SetCellValue(this.grid.RowsHierarchy.Items[8], columnItem3, "Vehicle 2 Gas");
    grid.CellsArea.SetCellValue(this.grid.RowsHierarchy.Items[9], columnItem3, "Vehicle 2 Maintenance");

    // fiil fourth column data.
    HierarchyItem columnItem4 = this.grid.ColumnsHierarchy.Items[4];
    grid.CellsArea.SetCellValue(this.grid.RowsHierarchy.Items[2], columnItem4, "$351,34");
    grid.CellsArea.SetCellValue(this.grid.RowsHierarchy.Items[3], columnItem4, "$55.12");
    grid.CellsArea.SetCellValue(this.grid.RowsHierarchy.Items[4], columnItem4, "$129.21");
    grid.CellsArea.SetCellValue(this.grid.RowsHierarchy.Items[5], columnItem4, "$55.17");
    grid.CellsArea.SetCellValue(this.grid.RowsHierarchy.Items[6], columnItem4, "$311.12");
    grid.CellsArea.SetCellValue(this.grid.RowsHierarchy.Items[7], columnItem4, "$109.35");
    grid.CellsArea.SetCellValue(this.grid.RowsHierarchy.Items[8], columnItem4, "$114.99");
    grid.CellsArea.SetCellValue(this.grid.RowsHierarchy.Items[9], columnItem4, "$35.19");
}

VB .NET

Private Sub SetCellsValues()
    Dim rowItem1 As HierarchyItem = grid.RowsHierarchy.Items(0)
    Dim columnItem1 As HierarchyItem = grid.ColumnsHierarchy.Items(0)

    grid.CellsArea.SetCellValue(rowItem1, columnItem1, "Monthly Housing and Transportation Expenses")
    grid.CellsArea.SetCellValue(grid.RowsHierarchy.Items(1), columnItem1, "Primary residence")
    grid.CellsArea.SetCellValue(grid.RowsHierarchy.Items(1), Me.grid.ColumnsHierarchy.Items(3), "Transportation Expenses")
    ' fill data

    grid.CellsArea.SetCellValue(Me.grid.RowsHierarchy.Items(2), columnItem1, "Mortgage Payment")
    grid.CellsArea.SetCellValue(Me.grid.RowsHierarchy.Items(3), columnItem1, "Property Tax")
    grid.CellsArea.SetCellValue(Me.grid.RowsHierarchy.Items(4), columnItem1, "Insurance")
    grid.CellsArea.SetCellValue(Me.grid.RowsHierarchy.Items(5), columnItem1, "Electricity")
    grid.CellsArea.SetCellValue(Me.grid.RowsHierarchy.Items(6), columnItem1, "Water")
    grid.CellsArea.SetCellValue(Me.grid.RowsHierarchy.Items(7), columnItem1, "Cabel TV Service")
    grid.CellsArea.SetCellValue(Me.grid.RowsHierarchy.Items(8), columnItem1, "High Speed Internet")

    ' fill second column data.
    Dim columnItem2 As HierarchyItem = Me.grid.ColumnsHierarchy.Items(1)
    grid.CellsArea.SetCellValue(Me.grid.RowsHierarchy.Items(2), columnItem2, "$1,459,76")
    grid.CellsArea.SetCellValue(Me.grid.RowsHierarchy.Items(3), columnItem2, "$212.54")
    grid.CellsArea.SetCellValue(Me.grid.RowsHierarchy.Items(4), columnItem2, "$49.21")
    grid.CellsArea.SetCellValue(Me.grid.RowsHierarchy.Items(5), columnItem2, "$73.44")
    grid.CellsArea.SetCellValue(Me.grid.RowsHierarchy.Items(6), columnItem2, "$41.48")
    grid.CellsArea.SetCellValue(Me.grid.RowsHierarchy.Items(7), columnItem2, "$22.14")
    grid.CellsArea.SetCellValue(Me.grid.RowsHierarchy.Items(8), columnItem2, "$24.99")

    ' fill third column data.

    Dim columnItem3 As HierarchyItem = Me.grid.ColumnsHierarchy.Items(3)
    grid.CellsArea.SetCellValue(Me.grid.RowsHierarchy.Items(2), columnItem3, "Vehicle 1 Payment")
    grid.CellsArea.SetCellValue(Me.grid.RowsHierarchy.Items(3), columnItem3, "Vehicle 1 Insurance")
    grid.CellsArea.SetCellValue(Me.grid.RowsHierarchy.Items(4), columnItem3, "Vehicle 1 Gas")
    grid.CellsArea.SetCellValue(Me.grid.RowsHierarchy.Items(5), columnItem3, "Vehicle 1 Maintenance")
    grid.CellsArea.SetCellValue(Me.grid.RowsHierarchy.Items(6), columnItem3, "Vehicle 2 Lease")
    grid.CellsArea.SetCellValue(Me.grid.RowsHierarchy.Items(7), columnItem3, "Vehicle 2 Insurance")
    grid.CellsArea.SetCellValue(Me.grid.RowsHierarchy.Items(8), columnItem3, "Vehicle 2 Gas")
    grid.CellsArea.SetCellValue(Me.grid.RowsHierarchy.Items(9), columnItem3, "Vehicle 2 Maintenance")

    ' fiil fourth column data.
    Dim columnItem4 As HierarchyItem = Me.grid.ColumnsHierarchy.Items(4)
    grid.CellsArea.SetCellValue(Me.grid.RowsHierarchy.Items(2), columnItem4, "$351,34")
    grid.CellsArea.SetCellValue(Me.grid.RowsHierarchy.Items(3), columnItem4, "$55.12")
    grid.CellsArea.SetCellValue(Me.grid.RowsHierarchy.Items(4), columnItem4, "$129.21")
    grid.CellsArea.SetCellValue(Me.grid.RowsHierarchy.Items(5), columnItem4, "$55.17")
    grid.CellsArea.SetCellValue(Me.grid.RowsHierarchy.Items(6), columnItem4, "$311.12")
    grid.CellsArea.SetCellValue(Me.grid.RowsHierarchy.Items(7), columnItem4, "$109.35")
    grid.CellsArea.SetCellValue(Me.grid.RowsHierarchy.Items(8), columnItem4, "$114.99")
    grid.CellsArea.SetCellValue(Me.grid.RowsHierarchy.Items(9), columnItem4, "$35.19")
    columnItem3.Width = 150
    columnItem1.Width = 150
    grid.Refresh()
End Sub

The MergeCells method will lllustrate how to merge grid cells by using the SetCellSpan method. When you use the SetCellSpan method, you need to pass four parameters to it - row, column, rows span and columns span. In the method we will merge cells in the first and second rows and we will also set custom visual style to the merged cells.

C#

private void MergeCells()
{
    HierarchyItem rowItem1 = grid.RowsHierarchy.Items[0];
    HierarchyItem columnItem1 = grid.ColumnsHierarchy.Items[0];

    // create a custom cell style.
    GridCellStyle style = new GridCellStyle();
    style.FillStyle = new FillStyleSolid(Color.FromArgb(255, 0, 175, 240));
    style.Font = new Font(this.Font.FontFamily, 11.0f, FontStyle.Bold);
    style.TextColor = Color.White;

    GridCellStyle orangestyle = new GridCellStyle();
    orangestyle.FillStyle = new FillStyleSolid(Color.FromArgb(255, 254, 122, 1));
    orangestyle.Font = new Font(this.Font.FontFamily, 10.0f, FontStyle.Bold);
    orangestyle.TextColor = Color.White;

    grid.CellsArea.SetCellTextAlignment(rowItem1, columnItem1, ContentAlignment.MiddleCenter);
    // set the cell span to 1 row and 5 columns.
    grid.CellsArea.SetCellSpan(rowItem1, columnItem1, 1, 5);
    // set the merged cell value and style.
    grid.CellsArea.SetCellDrawStyle(rowItem1, columnItem1, style);
    // set the cell span to 1 row and 2 columns.
    grid.CellsArea.SetCellSpan(grid.RowsHierarchy.Items[1], columnItem1, 1, 3);
    grid.CellsArea.SetCellDrawStyle(grid.RowsHierarchy.Items[1], columnItem1, orangestyle);
    // set the merged cell value.
    // set the cell span to 1 row and 2 columns.
    grid.CellsArea.SetCellSpan(grid.RowsHierarchy.Items[1], this.grid.ColumnsHierarchy.Items[3], 1, 2);
    // set the merged cell value.
    grid.CellsArea.SetCellDrawStyle(grid.RowsHierarchy.Items[1], this.grid.ColumnsHierarchy.Items[3], orangestyle);
}

VB .NET

Private Sub MergeCells()
    Dim rowItem1 As HierarchyItem = grid.RowsHierarchy.Items(0)
    Dim columnItem1 As HierarchyItem = grid.ColumnsHierarchy.Items(0)

    ' create a custom cell style.
    Dim style As New GridCellStyle()
    style.FillStyle = New FillStyleSolid(Color.FromArgb(255, 0, 175, 240))
    style.Font = New Font(Me.Font.FontFamily, 11.0f, FontStyle.Bold)
    style.TextColor = Color.White

    Dim orangestyle As New GridCellStyle()
    orangestyle.FillStyle = New FillStyleSolid(Color.FromArgb(255, 254, 122, 1))
    orangestyle.Font = New Font(Me.Font.FontFamily, 10.0f, FontStyle.Bold)
    orangestyle.TextColor = Color.White

    grid.CellsArea.SetCellTextAlignment(rowItem1, columnItem1, ContentAlignment.MiddleCenter)
    ' set the cell span to 1 row and 5 columns.
    grid.CellsArea.SetCellSpan(rowItem1, columnItem1, 1, 5)
    ' set the merged cell value and style.
    grid.CellsArea.SetCellDrawStyle(rowItem1, columnItem1, style)
    ' set the cell span to 1 row and 2 columns.
    grid.CellsArea.SetCellSpan(grid.RowsHierarchy.Items(1), columnItem1, 1, 3)
    grid.CellsArea.SetCellDrawStyle(grid.RowsHierarchy.Items(1), columnItem1, orangestyle)
    ' set the merged cell value.
    ' set the cell span to 1 row and 2 columns.
    grid.CellsArea.SetCellSpan(grid.RowsHierarchy.Items(1), Me.grid.ColumnsHierarchy.Items(3), 1, 2)
    ' set the merged cell value.
    grid.CellsArea.SetCellDrawStyle(grid.RowsHierarchy.Items(1), Me.grid.ColumnsHierarchy.Items(3), orangestyle)
End Sub

Sort WinForms DataGridView Rows and Columns by Label

by Admin 15. October 2011 21:16

VIBlend WinForms DataGridView has a built-in feature which allows you to set a custom Sort comparer. In this post, we will show you how to sort the DataGridView rows or columns by label.
At first, we will create a Comparer which compares HierarchyItem objects by the HierarchyItem.Caption property.

C#

private class ItemLabelComparer : IComparer<HierarchyItem>
{
    public int Compare(HierarchyItem item1, HierarchyItem item2)
    {
        return string.Compare(item1.Caption, item2.Caption);
    }
}

VB .NET

Private Class ItemLabelComparer
    Implements IComparer(Of HierarchyItem)
    Public Function Compare(ByVal item1 As HierarchyItem, ByVal item2 As HierarchyItem) As Integer
        Return String.Compare(item1.Caption, item2.Caption)
    End Function
End Class

Create an instance of the ItemLabelComparer object and pass it to the RowsHierarchy.SortBy method. If you want to sort the ColumnsHierarchy, call the ColumnsHierarchy.SortBy method.

C#

ItemLabelComparer Comparer = new ItemLabelComparer();
 this.vDataGridView1.RowsHierarchy.SortBy(this.vDataGridView1.ColumnsHierarchy.Items[0], sorting, Comparer);
this.Refresh();

VB .NET

Dim Comparer As New ItemLabelComparer()
 Me.vDataGridView1.RowsHierarchy.SortBy(Me.vDataGridView1.ColumnsHierarchy.Items(0), sorting, Comparer)
Me.Refresh()

Working with the VIBlend DataGrid and Nested Data Structures

by viblend 8. June 2011 22:29

This example demonstrates how to bind the VIBlend DataGrid for Silverlight to a list of invoices that has nested properties. The schema of data source contains the following DataFields / Properties: SalesPerson(string), ShipperCompany(string), ProductName(string), UnitPrice(double),
Quantity(double), Discount(double), ExtendedPrice(double), Freight(double) and Address(Address). The address object has the following properties: City(string), Region(string) and Country(string).

We'll create a Pivot Table with 3 pivot rows - City, Country and Region and 1 pivot column - Shipper Company.

<viblend:DataGrid ItemsSource="{Binding}" x:Name="dataGrid1" Margin="4" Background="White" AutoGenerateColumns="True">
    <viblend:DataGrid.BoundFields>
        <viblend:BoundField Text="Country" DataField="Address.Country" Width="160" SortMode="NotSortable"/>
        <viblend:BoundField Text="City" DataField="Address.City" Width="140" SortMode="NotSortable"/>
        <viblend:BoundField Text="Region" DataField="Address.Region" Width="140" SortMode="NotSortable"/>
        <viblend:BoundField Text="Carrier" DataField="ShipperCompany" Width="140" SortMode="NotSortable" />
        <viblend:BoundField Text="ExtendedPrice" DataField="ExtendedPrice" Width="140" SortMode="NotSortable" />
    </viblend:DataGrid.BoundFields>
    <viblend:DataGrid.BoundPivotRows>
        <viblend:BoundField Text="Country" DataField="Address.Country" Width="160" SortMode="NotSortable"/>
        <viblend:BoundField Text="Region" DataField="Address.Region" Width="160" SortMode="NotSortable"/>
        <viblend:BoundField Text="City" DataField="Address.City" Width="140" SortMode="NotSortable"/>
    </viblend:DataGrid.BoundPivotRows>
    <viblend:DataGrid.BoundPivotColumns>
        <viblend:BoundField Text="Carrier" DataField="ShipperCompany" Width="140" SortMode="NotSortable"/>
    </viblend:DataGrid.BoundPivotColumns>
    <viblend:DataGrid.BoundPivotValues>
        <viblend:BoundValueField Width="120" CellHorizontalContentAlignment="Center" Text="Count of Sales" Function="Count" DataField="ExtendedPrice"></viblend:BoundValueField>
         <viblend:BoundValueField Width="120" CellHorizontalContentAlignment="Right" CellVerticalContentAlignment="Center" CellTextFormatString="{}{0:C}" Text="Amount of Sales" Function="Sum" DataField="ExtendedPrice"></viblend:BoundValueField>
        <viblend:BoundValueField Width="120" CellHorizontalContentAlignment="Right" CellVerticalContentAlignment="Center" CellTextFormatString="{}{0:C}" Text="Avg Sale Amount" Function="Average" DataField="ExtendedPrice"></viblend:BoundValueField>
    </viblend:DataGrid.BoundPivotValues>
</viblend:DataGrid>

The following code generates the sample data in the example:

C#

public PivotTableDemo()
{
    InitializeComponent();
    PrepareGridData();
    this.DataContext = this.lst;
}

public class Invoice
{
    public Invoice(
        string City,
        string Region,
        string Country,
        string SalesPerson,
        string ShipperCompany,
        string ProductName,
        double UnitPrice,
        double Quantity,
        double Discount,
        double ExtendedPrice,
        double Freight)
    {
        this.SalesPerson = SalesPerson;
        this.Address = new Address();
        this.Address.City = City;
        this.Address.Region = string.IsNullOrEmpty(Region) ? "All Regions" : Region;
        this.Address.Country = Country;
        this.ShipperCompany = ShipperCompany;
        this.ProductName = ProductName;
        this.UnitPrice = UnitPrice;
        this.Quantity = Quantity;
        this.Discount = Discount;
        this.ExtendedPrice = ExtendedPrice;
        this.Freight = Freight;
    }

    public string SalesPerson { get; set; }
    public string ShipperCompany { get; set; }
    public Address Address { get; set; }
    public string ProductName { get; set; }
    public double UnitPrice { get; set; }
    public double Quantity { get; set; }
    public double Discount { get; set; }
    public double ExtendedPrice { get; set; }
    public double Freight { get; set; }
}

public class Address
{
    public string City { get; set; }
    public string Region { get; set; }
    public string Country { get; set; }
}

public List<Invoice> lst = new List<Invoice>();
private void PrepareGridData()
{
    try
    {
        StreamResourceInfo sri = Application.GetResourceStream(new Uri("IntegratedDemo;component/Examples/Grid/invoices.tab", UriKind.Relative));
        System.IO.StreamReader sr = new System.IO.StreamReader(sri.Stream);
        string line = null;
        sr.ReadLine();
        while ((line = sr.ReadLine()) != null)
        {
            string[] tabs = line.Split('\t');
            lst.Add(new Invoice(tabs[0], tabs[1], tabs[2], tabs[3], tabs[4], tabs[5], double.Parse(tabs[6]), double.Parse(tabs[7]), double.Parse(tabs[8]), double.Parse(tabs[9]), double.Parse(tabs[10])));
        }
        sr.Close();
    }
    catch (System.Exception)
    {
    }
}

VB .NET

Public Sub New()
    InitializeComponent()
    PrepareGridData()
    Me.DataContext = Me.lst
End Sub

Public Class Invoice
    Public Sub New(ByVal City As String, ByVal Region As String, ByVal Country As String, ByVal SalesPerson As String, ByVal ShipperCompany As String, ByVal ProductName As String, ByVal UnitPrice As Double, ByVal Quantity As Double, ByVal Discount As Double, ByVal ExtendedPrice As Double, ByVal Freight As Double)
        Me.SalesPerson = SalesPerson
        Me.Address = New Address()
        Me.Address.City = City
        Me.Address.Region = If(String.IsNullOrEmpty(Region), "All Regions", Region)
        Me.Address.Country = Country
        Me.ShipperCompany = ShipperCompany
        Me.ProductName = ProductName
        Me.UnitPrice = UnitPrice
        Me.Quantity = Quantity
        Me.Discount = Discount
        Me.ExtendedPrice = ExtendedPrice
        Me.Freight = Freight
    End Sub

    Private privateSalesPerson As String
    Public Property SalesPerson() As String
        Get
            Return privateSalesPerson
        End Get
        Set(ByVal value As String)
            privateSalesPerson = value
        End Set
    End Property
    Private privateShipperCompany As String
    Public Property ShipperCompany() As String
        Get
            Return privateShipperCompany
        End Get
        Set(ByVal value As String)
            privateShipperCompany = value
        End Set
    End Property
    Private privateAddress As Address
    Public Property Address() As Address
        Get
            Return privateAddress
        End Get
        Set(ByVal value As Address)
            privateAddress = value
        End Set
    End Property
    Private privateProductName As String
    Public Property ProductName() As String
        Get
            Return privateProductName
        End Get
        Set(ByVal value As String)
            privateProductName = value
        End Set
    End Property
    Private privateUnitPrice As Double
    Public Property UnitPrice() As Double
        Get
            Return privateUnitPrice
        End Get
        Set(ByVal value As Double)
            privateUnitPrice = value
        End Set
    End Property
    Private privateQuantity As Double
    Public Property Quantity() As Double
        Get
            Return privateQuantity
        End Get
        Set(ByVal value As Double)
            privateQuantity = value
        End Set
    End Property
    Private privateDiscount As Double
    Public Property Discount() As Double
        Get
            Return privateDiscount
        End Get
        Set(ByVal value As Double)
            privateDiscount = value
        End Set
    End Property
    Private privateExtendedPrice As Double
    Public Property ExtendedPrice() As Double
        Get
            Return privateExtendedPrice
        End Get
        Set(ByVal value As Double)
            privateExtendedPrice = value
        End Set
    End Property
    Private privateFreight As Double
    Public Property Freight() As Double
        Get
            Return privateFreight
        End Get
        Set(ByVal value As Double)
            privateFreight = value
        End Set
    End Property
End Class

Public Class Address
    Private privateCity As String
    Public Property City() As String
        Get
            Return privateCity
        End Get
        Set(ByVal value As String)
            privateCity = value
        End Set
    End Property
    Private privateRegion As String
    Public Property Region() As String
        Get
            Return privateRegion
        End Get
        Set(ByVal value As String)
            privateRegion = value
        End Set
    End Property
    Private privateCountry As String
    Public Property Country() As String
        Get
            Return privateCountry
        End Get
        Set(ByVal value As String)
            privateCountry = value
        End Set
    End Property
End Class

Public lst As List(Of Invoice) = New List(Of Invoice)()
Private Sub PrepareGridData()
    Try
        Dim sri As StreamResourceInfo = Application.GetResourceStream(New Uri("IntegratedDemo;component/Examples/Grid/invoices.tab", UriKind.Relative))
        Dim sr As New System.IO.StreamReader(sri.Stream)
        Dim line As String = Nothing
        sr.ReadLine()
        line = sr.ReadLine()
        Do While line IsNot Nothing
            Dim tabs() As String = line.Split(ControlChars.Tab)
            lst.Add(New Invoice(tabs(0), tabs(1), tabs(2), tabs(3), tabs(4), tabs(5), Double.Parse(tabs(6)), Double.Parse(tabs(7)), Double.Parse(tabs(8)), Double.Parse(tabs(9)), Double.Parse(tabs(10))))
            line = sr.ReadLine()
        Loop
        sr.Close()
    Catch e1 As System.Exception
    End Try
End Sub


Note: The 'invoices.tab' file is included in the installation package of VIBlend Controls for Silverlight. The default path to the file is: C:\Program Files\VIBlend\SilverlightControls v.5.0\Source Code\CSharp\Examples\Grid\invoices.tab.

Silverlight DataGrid – Custom Sorting using SortDescription

by viblend 8. April 2011 19:15

This post will show you how to override the built-in sorting functionality and sort the DataGrid data using the SortDescription class. The data content is sorted when a user clicks a column header.

1. The following example defines a DataGrid with six columns that bind to the Name, Date, Product, Quantity, UnitPrice and SalesAmount properties of the EmployeeSaleRecord class.

     <viblendDataGrid:DataGrid AutoGenerateColumns="True" Height="200" VerticalAlignment="Center" Name="dataGrid" Width="350">
            <viblendDataGrid:DataGrid.BoundFields>               
                <viblendDataGrid:BoundField Text="Name" DataField="Name" Width="160"  CellStyle="{StaticResource textCentered}"/>
                <viblendDataGrid:BoundField Text="Date" DataField="Date" Width="140" />
                <viblendDataGrid:BoundField Text="Product" DataField="Product" Width="140"  CellStyle="{StaticResource textCentered}"/>
                <viblendDataGrid:BoundField Text="Quantity" DataField="Quantity" Width="90"  CellStyle="{StaticResource textCentered}"/>
                <viblendDataGrid:BoundField Text="Unit Price" DataField="UnitPrice" Width="74"/>
                <viblendDataGrid:BoundField Text="Sales Amount" DataField="SalesAmount" Width="88"/>
            </viblendDataGrid:DataGrid.BoundFields>
        </viblendDataGrid:DataGrid>


2. Create column header templates with up and down arrow elements that will be displayed when the grid data is sorted.

    <UserControl.Resources>
        <Style x:Name="textCentered" TargetType="viblendDataGrid:GridCellElement">
            <Setter Property="HorizontalContentAlignment" Value="Center" />
            <Setter Property="VerticalContentAlignment" Value="Center" />
        </Style>

        <DataTemplate x:Key="SortAscendingTemplate">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"></ColumnDefinition>
                    <ColumnDefinition Width="Auto"></ColumnDefinition>
                </Grid.ColumnDefinitions>
                <TextBlock Text="{Binding}"></TextBlock>
                <Path Grid.Column="1" x:Name="sortAscElement" Height="5" Width="9" Stretch="Fill" Stroke="#FFFFFFFF" Data="M4.5,5 L0,0 L9,0 z" RenderTransformOrigin="0.0,0.0">
                    <Path.Fill>
                        <LinearGradientBrush EndPoint="-0.237,0.525" StartPoint="0.679,0.525">
                            <GradientStop Color="#55FFFFFF"/>
                            <GradientStop Color="#55FFFFFF" Offset="0.991"/>
                        </LinearGradientBrush>
                    </Path.Fill>
                </Path>
            </Grid>
        </DataTemplate>
        <DataTemplate x:Key="SortDescendingTemplate">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"></ColumnDefinition>
                    <ColumnDefinition Width="Auto"></ColumnDefinition>
                </Grid.ColumnDefinitions>
                <TextBlock Text="{Binding}"></TextBlock>
                <Path Grid.Column="1" x:Name="sortDescElement" Height="5" Width="9" Stretch="Fill" Stroke="#FFFFFFFF" Data="M4.5,0 L9,5 L0,5 z" RenderTransformOrigin="0.0,0.0" >
                    <Path.Fill>
                        <LinearGradientBrush EndPoint="-0.237,0.525" StartPoint="0.679,0.525">
                            <GradientStop Color="#55FFFFFF"/>
                            <GradientStop Color="#55FFFFFF" Offset="0.991"/>
                        </LinearGradientBrush>
                    </Path.Fill>
                </Path>
            </Grid>
        </DataTemplate>
    </UserControl.Resources>


3. Create  CollectionViewSource, HierarchyItem and bool? fields in the code behind.
4. Bind the DataGrid to a List of EmployeeSaleRecord objects. Set the selection mode to row selection and hide the row headers.

    C#

    // Bind DataGrid
    dataGrid.ItemsSource = listSaleRecord;
    dataGrid.SelectionMode = DataGrid.SELECTION_MODE.FULL_ROW_SELECT;
    dataGrid.RowsHierarchy.Visible = false; 

     VB .NET
    ' Bind DataGrid
    dataGrid.ItemsSource = listSaleRecord
    dataGrid.SelectionMode = DataGrid.SELECTION_MODE.FULL_ROW_SELECT
    dataGrid.RowsHierarchy.Visible = False

5. To sort the data according to the contents of a column, the example defines an event handler to handle the HierarchyItemMouseClick event that occurs when you press the column header.  In the event handler, toggle the sorting order and set the DataTemplate property of the HierarchyItem object depending on the sort order. Call the Sort method and  set the DataGrid.ItemsSource property to point to the view. Doing this, the DataGrid will be refreshed and sorted.
      

       C#
       // Subscribe to HierarchyItemMouseClick event.
      dataGrid.HierarchyItemMouseClick += new DataGrid.HierarchyItemMouseButtonEventHandler(dataGrid_HierarchyItemMouseClick);

      void dataGrid_HierarchyItemMouseClick(object sender, HierarchyItemMouseButtonEventArgs args)
        {
            if (clickedItem != null && !args.HierarchyItem.BoundField.DataField.Equals(clickedItem.BoundField.DataField))
            {
                clickedItem.BoundField.DataTemplate = null;
                ascending = null;
            }

            clickedItem = args.HierarchyItem;
            clickedItem.BoundField.DataContext = clickedItem.BoundField.DataField;

            // Load the column's DataTemplate
            if (ascending == null)
            {
                ascending = true;
                clickedItem.BoundField.DataTemplate = this.Resources["SortDescendingTemplate"] as DataTemplate;
            }
            else if (ascending.HasValue && !ascending.Value)
            {
                ascending = null;
                clickedItem.BoundField.DataTemplate = null;
            }
            else if (ascending.HasValue && ascending.Value)
            {
                ascending = false;
                clickedItem.BoundField.DataTemplate = this.Resources["SortAscendingTemplate"] as DataTemplate;
            }

            if (ascending == null)
            {
                dataGrid.ItemsSource = listSaleRecord;
            }
            else
            {
                SortDescription sortDescription = new SortDescription(args.HierarchyItem.BoundField.DataField, ascending == true ? ListSortDirection.Ascending : ListSortDirection.Descending);
                ICollectionView view = Sort(sortDescription, args.HierarchyItem.BoundField.DataField, this.listSaleRecord);
                dataGrid.ItemsSource = view;
            }
        }

      VB .NET

      ' Subscribe to HierarchyItemMouseClick event.
      Private dataGrid.HierarchyItemMouseClick += New DataGrid.HierarchyItemMouseButtonEventHandler(AddressOf dataGrid_HierarchyItemMouseClick)

      Private Sub dataGrid_HierarchyItemMouseClick(ByVal sender As Object, ByVal args As HierarchyItemMouseButtonEventArgs)
            If clickedItem IsNot Nothing AndAlso (Not args.HierarchyItem.BoundField.DataField.Equals(clickedItem.BoundField.DataField)) Then
                clickedItem.BoundField.DataTemplate = Nothing
                ascending = Nothing
            End If

            clickedItem = args.HierarchyItem
            clickedItem.BoundField.DataContext = clickedItem.BoundField.DataField

            ' Load the column's DataTemplate
            If ascending Is Nothing Then
                ascending = True
                clickedItem.BoundField.DataTemplate = TryCast(Me.Resources("SortDescendingTemplate"), DataTemplate)
            ElseIf ascending.HasValue AndAlso (Not ascending.Value) Then
                ascending = Nothing
                clickedItem.BoundField.DataTemplate = Nothing
            ElseIf ascending.HasValue AndAlso ascending.Value Then
                ascending = False
                clickedItem.BoundField.DataTemplate = TryCast(Me.Resources("SortAscendingTemplate"), DataTemplate)
            End If

            If ascending Is Nothing Then
                dataGrid.ItemsSource = listSaleRecord
            Else
                Dim sortDescription As New SortDescription(args.HierarchyItem.BoundField.DataField,If(ascending = True, ListSortDirection.Ascending, ListSortDirection.Descending))
                Dim view As ICollectionView = Sort(sortDescription, args.HierarchyItem.BoundField.DataField, Me.listSaleRecord)
                dataGrid.ItemsSource = view
            End If
      End Sub

6. Implement the Sort method. Add the SortDescription instance to the CollectionViewSource and return the view which will be used as DataGrid items source.

      C#

       public virtual ICollectionView Sort(SortDescription sortDescription, string columnName, System.Collections.IEnumerable itemsSource)
        {
            if (sortDescription == null)
                return null;

            string displayMember = columnName;

            if (String.IsNullOrEmpty(displayMember))
            {
                displayMember = "";
            }

            viewSource.SortDescriptions.Clear();
            if (itemsSource != null)
            {
                if (itemsSource as ICollectionView != null)
                {
                    viewSource.Source = (itemsSource as ICollectionView).SourceCollection;
                }
                else
                {
                    viewSource.Source = itemsSource;
                }

                viewSource.SortDescriptions.Add(sortDescription);
                return viewSource.View;
            }

            return null;
        }

     VB .NET

     Public Overridable Function Sort(ByVal sortDescription As SortDescription, ByVal columnName As String, ByVal itemsSource As System.Collections.IEnumerable) As ICollectionView
            If sortDescription Is Nothing Then
                Return Nothing
            End If

            Dim displayMember As String = columnName

            If String.IsNullOrEmpty(displayMember) Then
                displayMember = ""
            End If

            viewSource.SortDescriptions.Clear()
            If itemsSource IsNot Nothing Then
                If TryCast(itemsSource, ICollectionView) IsNot Nothing Then
                    viewSource.Source = (TryCast(itemsSource, ICollectionView)).SourceCollection
                Else
                    viewSource.Source = itemsSource
                End If

                viewSource.SortDescriptions.Add(sortDescription)
                Return viewSource.View
            End If

            Return Nothing
     End Function

 

Download demo project: DataGridCustomSortingDemo.zip

DataGrid Mask Column

by viblend 23. January 2011 08:09

The mask editor control ensures a formatted appearance to underlying string values and also validates the user input. This post demonstrates how to create a mask column in VIBlend DataGrid for Silverlight.

1. At first, create the DataGrid control and set up the binding expressions.  We setup the first column to display a string value and the second column with a phone number mask “(###) ###-####″. The MaskEditor’s EditorValue property is bound to the PhoneNumber property in the data source.

  <Grid x:Name="LayoutRoot" Background="White">
    <Grid.Resources>
        <local:PhoneNumberConverter x:Key="PhoneNumberConverter"></local:PhoneNumberConverter>

        <DataTemplate x:Key="cellEditMaskEditorTemplate">
            <viblendEditors:MaskEditor FontSize="9" Mask="(###) ###-####" EditorValue="{Binding PhoneNumber, Mode=TwoWay, Converter={StaticResource PhoneNumberConverter}}"/>
        </DataTemplate>
    </Grid.Resources>
    <viblendDataGrid:DataGrid ItemsSource="{Binding}" Name="dataGrid1" Margin="10">
        <viblendDataGrid:DataGrid.BoundFields>
            <viblendDataGrid:BoundField Text="Name" DataField="Name" Width="175" SortMode="Automatic"/>
            <viblendDataGrid:BoundField Text="Phone Number" DataField="PhoneNumber" CellEditorActivationFlags="MOUSE_CLICK_SELECTED_CELL" CellEditorDeActivationFlags="MOUSE_CLICK" CellEditTemplate="{StaticResource cellEditMaskEditorTemplate}" Width="175"/>
        </viblendDataGrid:DataGrid.BoundFields>
    </viblendDataGrid:DataGrid>
</Grid>

 

2.. Populate the DataGrid.

C#

public partial class MainPage : UserControl
 {
        public MainPage()
        {

            InitializeComponent();

            List<User> users = new List<User>();

            for (int i = 0; i < 3; i++)
            {
                User user = new User(name[i], phones[i]);
                users.Add(user);
            }

            this.DataContext = users;
        }

        public class User
        {
            public User(string name, string phoneNumber)
            {
                this.Name = name;
                this.PhoneNumber = phoneNumber;
            }

            public string Name
            {
                get;
                set;
            }

            public string PhoneNumber
            {
                get;
                set;
            }
        }
 

        string[] name = new string[]
                {
                    "Andrew",
                    "Nancy",
                    "Shelley",
                };

        string[] phones = new string[]
                {
                    "(617) 245-9601",
                    "(615) 621-2121",
                    "(612) 555-3251",
                };
    }

 VB .NET

Partial Public Class MainPage
    Inherits UserControl
        Public Sub New()

            InitializeComponent()

            Dim users As List(Of User) = New List(Of User)()

            For i As Integer = 0 To 2
                Dim user As New User(name(i), phones(i))
                users.Add(user)
            Next i

            Me.DataContext = users
        End Sub

        Public Class User
            Public Sub New(ByVal name As String, ByVal phoneNumber As String)
                Me.Name = name
                Me.PhoneNumber = phoneNumber
            End Sub

            Private privateName As String
            Public Property Name() As String
                Get
                    Return privateName
                End Get
                Set(ByVal value As String)
                    privateName = value
                End Set
            End Property

            Private privatePhoneNumber As String
            Public Property PhoneNumber() As String
                Get
                    Return privatePhoneNumber
                End Get
                Set(ByVal value As String)
                    privatePhoneNumber = value
                End Set
            End Property
        End Class


        Private name() As String = { "Andrew", "Nancy", "Shelley" }

        Private phones() As String = { "(617) 245-9601", "(615) 621-2121", "(612) 555-3251" }
End Class

3. In order to format a grid cell value into a MaskEditor.EditorValue, create a class that implements the IValueConverter interface and then implement the Convert and ConvertBack methods. The following code snippet shows the implementation of a phone-number converter that converts the grid cell value passed in so that it displays it in the MaskEditor.

C#

public class PhoneNumberConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        string valueString = value.ToString();
        string phoneNumberString = "";
        for (int i = 0; i
<valueString.Length; i++)
        {
            if (Char.IsDigit(valueString[i]))
            {
                phoneNumberString += valueString[i];
            }
        }

        return phoneNumberString;
    }

    public object ConvertBack(object value, Type targetType,
        object parameter, System.Globalization.CultureInfo culture)
    {
        if (value != null)
        {
            string phoneString = value.ToString();

            if (phoneString.Length >0)
            {
                phoneString = phoneString.Insert(0, "(");
            }

            if (phoneString.Length > 4)
            {
                phoneString = phoneString.Insert(4, ")");
            }

            if (phoneString.Length > 8)
            {
                phoneString = phoneString.Insert(8, "-");
            }

            return phoneString;
        }
        else
        {
            return "";
        }
    }
}

VB .NET

 Public Class PhoneNumberConverter
    Implements IValueConverter
    Public Function Convert(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object
        Dim valueString As String = value.ToString()
        Dim phoneNumberString As String = ""
        For i As Integer = 0 To valueString.Length - 1
            If Char.IsDigit(valueString.Chars(i)) Then
                phoneNumberString &= valueString.Chars(i)
            End If
        Next i

        Return phoneNumberString
    End Function

    Public Function ConvertBack(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object
        If value IsNot Nothing Then
            Dim phoneString As String = value.ToString()

            If phoneString.Length >0 Then
                phoneString = phoneString.Insert(0, "(")
            End If

            If phoneString.Length > 4 Then
                phoneString = phoneString.Insert(4, ")")
            End If

            If phoneString.Length > 8 Then
                phoneString = phoneString.Insert(8, "-")
            End If

            Return phoneString
        Else
            Return ""
        End If
    End Function
End Class

 

 

 

First Look at the new themes for Silverlight

by viblend 29. October 2010 07:24

We are coming close to yet another big release of VIBlend Controls for Silverlight. In the last 2 months, we spent much time on samples, themes and documentation. With the new release you will get 4 new themes for all of our controls.




Another highly anticipated addition to our DataGrid control is the enhanced cells and headers styling.



We will be glad to hear your comments or ideas about what can be improved in our Silverlight suite, so that it may be further extended and enabled with useful features.

VIBlend Silverlight Controls v3.0 - Released

by viblend 14. September 2010 20:47

VIBlend is announcing the immediate availability of the VIBlend Controls for Silverlight ver. 3.0.

With 19 new controls, Themes and enhanced functionality in the DataGrid, Menu and SpinEditor, VIBlend Controls for Silverlight empower developers to build full featured and great looking line-of-business applications.

New features:

  • Menu and ContextMenu controls now have 17 built-in Themes including Office 2010 Blue, Black and Silver and Office 2007 Blue, Black and Silver
  • DataGrid Enhancements  - The latest release introduces Export to Excel, CSV, HTML and XML.
  • 19 new editors such as ComboBox, ListBox, CheckedListBox, GroupBox, ColorPicker, RadioButton, CheckBox, Slider, Button, ToggleButton, etc.
  • Data Input Editors and NavigationPane now have an improved Data Binding capabilities.
See our Silverlight Controls Live Demo and Download a free trial today.

About the author

Some text that describes me

Tag cloud

Recent comments

Comment RSS
Copyright © 2011 VIBlend  
ALL RIGHTS RESERVED  
 
Terms of Use | Privacy Policy
WinForms Controls Purchase Online About Us
       
DataGrid Navigation Pane Technical Support Blog
ScrollBar TreeView
ListBox ProgressBar Downloads Register
ComboBox Buttons
TabControl Editors Documentation Client Login

VIBlend Blog is powered by BlogEngine.NET