VIBlend
Home Products Downloads Purchase Support Forum About Blog

What's coming with VIBlend WinForms Controls 9.0

by viblend 3. March 2012 21:20
In the next version of VIBlend, we will enhance the vDataGridView control by adding a new Search capabilities to it. Users will be able to choose a search criteria and easily find a Row in the Grid. This new feature can be turned on by drag and drop of a vDataGridViewSearchHeader control and setting its DataGridView property to point to your vDataGridView instance.
 
  

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.

VIBlend extends the WinForms DataGridView with new features

by viblend 13. February 2011 08:44

The new version of VIBlend Controls for WinForms is coming in a few weeks and will deliver an upgrade to the DataGridView control with new features, better UI and styling capabilities.

-  Extended filtering options

The DataGridView filtering window will be extended by providing an easier and user-friendly experience. The new filtering window will show a checked list, allowing for single and/or multiple selections. The previous filtering mechanism will still be available and you will be able to switch to it by clicking a single button. The filtering improvements will also include new case-sensitive filtering options.



-    Improved support for Totals

The Pivot-Table totals support will be extended by adding a capability that will allow you to display Sub-Totals, Grand-Totals or a combination of Sub-Totals and Grand-Totals

-    New Cell Editors

The new version will include several new cell editors – Currency, Percentage, Number, Mask and Fixed-Point Editors

-    New Pivot-Table Filtering and enhanced Pivot-Design panel

The DataGridView will expose a new BoundFieldsFilters collection that will allow you to filter data in the Pivot-Table and display only a subset of data that meet the filtering criteria (criteria: Conditions you specify to limit which records are included in the result set of a filter.) that you specify and hides data that you do not want displayed. The Pivot-Design panel will feature a new Filter Area box that will enable you to manipulate the BoundFieldsFilters collection by drag and drop. Another addition to the Pivot-Design panel will be the Localization support.

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

 

 

 

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