VIBlend
Home Products Downloads Purchase Support Forum About Blog

How to bind a WPF Pivot Grid to MS Access Database

by viblend 11. December 2010 19:58

In this post we will demonstrate you how to bind the VIBlend WPF DataGrid to "Invoices" view in the Nwind.mdb database, which is shipped with the installation. The control will be used to analyze sales per country and shippers companies.

At first you need to create a new instance of the NwindDataSet and InvoicesTableAdapter. Then you need to fill the table with data and set the DataContext property.

C#

NwindDataSet dataSet = new NwindDataSet();
InvoicesTableAdapter adapter = new InvoicesTableAdapter();
adapter.Fill(dataSet.Invoices);
this.DataContext = dataSet.Invoices;

VB .NET

Dim dataSet As New NwindDataSet()
Dim adapter As New InvoicesTableAdapter()
adapter.Fill(dataSet.Invoices)
Me.DataContext = dataSet.Invoices

The DataGrid fields that will represent data source fields are created in XAML markup. In order to format the currency data, you should specify the StringFormat property in the binding expression.

 <Window x:Class="DataBinding.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:DataBinding"
        Title="MainWindow" Height="350" Width="525" xmlns:viblendDataGrid="clr-namespace:VIBlend.WPF.Controls;assembly=VIBlend.WPF.DataGrid">
    <Grid>
        <Grid.Resources>
            <DataTemplate x:Key="CellTemplate">
                <TextBlock HorizontalAlignment="Right" Text="{Binding StringFormat=C2}"/>
            </DataTemplate>
        </Grid.Resources>
        <viblendDataGrid:DataGrid ItemsSource="{Binding}" Name="dataGrid1" Margin="10">
            <viblendDataGrid:DataGrid.BoundFields>
                <viblendDataGrid:BoundField Text="Shippers Company" DataField="Shippers_CompanyName"/>
                <viblendDataGrid:BoundField Text="Country" DataField="Country"/>
                <viblendDataGrid:BoundField Text="ExtendedPrice" DataField="ExtendedPrice"/>
            </viblendDataGrid:DataGrid.BoundFields>
            <viblendDataGrid:DataGrid.BoundPivotRows>
                <viblendDataGrid:BoundField Width="100" Text="Country" DataField="Country"/>
            </viblendDataGrid:DataGrid.BoundPivotRows>
            <viblendDataGrid:DataGrid.BoundPivotColumns>
                <viblendDataGrid:BoundField Text="Shippers Company" DataField="Shippers_CompanyName"/>
            </viblendDataGrid:DataGrid.BoundPivotColumns>
            <viblendDataGrid:DataGrid.BoundPivotValues>
                <viblendDataGrid:BoundValueField CellDataTemplate="{StaticResource CellTemplate}" Text="Sum" DataField="ExtendedPrice" Function="Sum"/>
                <viblendDataGrid:BoundValueField CellDataTemplate="{StaticResource CellTemplate}" Text="Average Price" DataField="ExtendedPrice" Function="Average"/>
            </viblendDataGrid:DataGrid.BoundPivotValues>
        </viblendDataGrid:DataGrid>
    </Grid>
</Window>

Here is an image of the result:

VIBlend Controls for WPF v3.0 - Released

by viblend 5. December 2010 19:14

We are happy to announce the immediate availability of VIBlend Controls for WPF v3.0 - UI Controls for high performance, WPF user interfaces.  VIBlend Controls for WPF includes a shared API with VIBlend Controls for Silverlight and comes with fast data binding that can easily handle hundreds of thousands records.

What’s new in VIBlend Controls for WPF v3.0?

New Controls:

- TabControl, GroupBox, ColorPicker, DropDownButton, SplitButton, RadioButton, CheckBox, Button, ToggleButton, RepeatButton, ScrollViewer, LinkLabel.

Improved:

- All themes get a major facelift for greater consistency and appeal across skin elements such as headers, rows, buttons, scrollbars, selected, default, highlighted, disabled states, etc.

- DataGrid - performance optimizations, support for data binding to a DataTable, cells and headers styling, added scrolling animations, localization support, clipboard operations - Cut(CTRL + X), Copy(CTRL + C) and Paste(CTRL + V), better cells highlight functionality with ability to highlight all cells in a row or column.

New Free Themes:

- Silver, Office2007 Blue, Office2007  Black and Office2007  Silver

  If you want to check out the latest release, it is now available for download.

Free Themes for the standard WPF controls

by viblend 5. December 2010 11:15

In the new release of VIBlend WPF Controls we will extend our collection of Free Themes for the standard WPF controls. The collection will include Office2010 Blue, Black and Silver, Office 2007 Blue, Black and Silver and one additional brand new theme that we called ‘Silver’. All of these themes are provided for free without any restrictions. You can use them in your commercial projects and non-commercial projects totally free of charge.

Here are a few screenshots of the new themes:

- Office2007 Black

- Office2007 Blue 


- Office2007 Silver

- Silver

How to bind the VIBlend DataGrid for Silverlight and WPF to Indexed properties?

by viblend 3. September 2010 19:48

In order to bind the VIBlend DataGrid to indexed properties, you need to do the following:

1. Create DataTemplates that are bound to indexed properties.

        <DataTemplate x:Key="LastNameCellTemplate">
            <Grid>
                <TextBlock Text="{Binding [LastName], Mode=OneWay}"/>
            </Grid>
        </DataTemplate>

        <DataTemplate x:Key="FirstNameCellTemplate">
            <Grid>
                <TextBlock Text="{Binding [FirstName], Mode=OneWay}"/>
            </Grid>
        </DataTemplate>

2. Create a new DataGrid instance. Set the CellDataTemplate property of the DataGrid’s BoundFields to point to the DataTemplates.

        <viblend:DataGrid x:Name="dataGrid" Width="400" Height="280" AutoGenerateColumns="True">
            <viblend:DataGrid.BoundFields>
                <viblend:BoundField Text="FirstName" Width="150" CellDataTemplate="{StaticResource FirstNameCellTemplate}"/>
                <viblend:BoundField Text="LastName" Width="150" CellDataTemplate="{StaticResource LastNameCellTemplate}"/>
            </viblend:DataGrid.BoundFields>
        </viblend:DataGrid>

3.  Create a new class that will represent a single record of the DataGrid.

CSharp

public class Person : INotifyPropertyChanged
{   
    public Person()
    {
    }

    private Dictionary<string, object> data = new Dictionary<string, object>();

    public object this[string key]
    {
        get
        {
            if (!data.ContainsKey(key))
            {
                data[key] = null;
            }
            return data[key];
        }
        set
        {
            data[key] = value;
            if (this.PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(""));
            }
        }
    }

    public IEnumerable<string> Keys
    {
        get
        {
            return data.Keys;
        }
    }

    public event PropertyChangedEventHandler PropertyChanged;
}

VB .NET

Public Class Person
    Implements INotifyPropertyChanged
    Public Sub New()
    End Sub

    Private data As Dictionary(Of String, Object) = New Dictionary(Of String, Object)()

    Default Public Property Item(ByVal key As String) As Object
        Get
            If (Not data.ContainsKey(key)) Then
                data(key) = Nothing
            End If
            Return data(key)
        End Get
        Set(ByVal value As Object)
            data(key) = value
            RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(""))
        End Set
    End Property

    Public ReadOnly Property Keys() As IEnumerable(Of String)
        Get
            Return data.Keys
        End Get
    End Property

    Public Event PropertyChanged As PropertyChangedEventHandler
End Class

4.  Create a new generic List of Person objects and set the ItemsSource property of the DataGrid, in order to bind it to the list.

CSharp

       List<Person> listOfPersons = new List<Person>();
       for (int i = 0; i < 10; i++)
       {
           Person person = new Person();
           person["FirstName"] = "FirstName" + i;
           person["LastName"] = "LastName" + i;
           listOfPersons.Add(person);
       }
       this.dataGrid.ItemsSource = listOfPersons;

VB .NET

      Dim listOfPersons As List(Of Person) = New List(Of Person)()
      For i As Integer = 0 To 9
         Dim person As New Person()
         person("FirstName") = "FirstName" & i
         person("LastName") = "LastName" & i
         listOfPersons.Add(person)
      Next i
      Me.dataGrid.ItemsSource = listOfPersons

VIBlend WPF Controls v2.0 - Released

by viblend 10. August 2010 08:13
VIBlend  is proud to announce the immediate availability of the VIBlend WPF Controls ver. 2.0 – feature complete WPF components for Visual Studio 2008 and Visual Studio 2010. In this new release, VIBlend introduces several new controls and adds numerous new features to the existing controls.

New controls include:
  • WPF DataGrid/PivotGrid control
  • WPF OutlookPane
  • WPF NavigationPane
  • WPF ScrollablePanel
  • WPF SpinEditor
  • WPF PromptTextBox
  • WPF DateTimePicker
  • WPF CheckedListBox
Updates and new features:
  • Help Documentation
  • Editors Themes
  • Editors Data Binding capabilities
  • Editors Clipboard support
  • Editors Keyboard Navigation
  • Editors now have a built-in validation
  • DateTimeEditor now have a support for Null Values
  • VS2010 and VS2008 toolbox integration
New Themes:
  • Office2010Black
  • Office2010Blue
  • Office2010Silver
  • Office2007Blue
  • Office2007Silver
  • Office2007Black
Note: The Office2010 themes include a set of free styles for the standard WPF controls.

To download your free evaluation copy of VIBlend WPF Controls ver. 2.0, login into your account and visit our product download page at: http://www.viblend.com/downloads.aspx

Using VIBlend DataGridView for WinForms in a WPF Application

by viblend 3. April 2010 21:56

In this blog post we will show you how to use the VIBlend DataGridView for WinForms in a WPF application.

The following code example creates a WinForms DataGrid control with Office2010Black theme in a WPF application. This example uses a WindowsFormsHost element to place the DataGrid control within the main window’s root  element. The WindowsFormsHost element could be found in the WindowsFormsIntegration.dll.

[xaml]

  <Window x:Class="HostWinFormsControlInWPF.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:viblend="clr-namespace:VIBlend.WinForms.DataGridView;assembly=VIBlendGrid"
        Title="Window1" Height="300" Width="300">
    <Grid>
        <WindowsFormsHost>
            <viblend:vDataGridView x:Name="VIBlendDataGrid" VIBlendTheme="OFFICE2010BLACK"/>               
        </WindowsFormsHost>
    </Grid>
</Window>

In order to bind the data grid, you need to do the following:  Click on the Data menu item in your Visual Studio, then select the “Add new DataSource” item.  Browse to the Nwind.mdb which ships with the WinForms controls installation, choose the Employees table and click finish. In the code behind, after the InitializeComponent call or in the Load event handler , bind the data grid to the Employees table.

            NwindDataSet dataSet = new NwindDataSet();
            EmployeesTableAdapter adapter = new EmployeesTableAdapter();
            adapter.Fill(dataSet.Employees);
            this.VIBlendDataGrid.DataSource = dataSet.Employees.DefaultView;
            this.VIBlendDataGrid.DataBind();

Here is the result:

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