VIBlend
Home Products Downloads Purchase Support Forum About Blog

Creating Rows and Columns Hierarchies in Unbound Mode

by viblend 3. April 2012 16:46

In this post, we will show you how to create rows and column hierarchies in unbound mode and fill the DataGrid cells with data. In order the add Columns in unbound mode, you should use the DataGrid.ColumnsHierarchy.Items.Add method. To add rows in unbound mode, use the DataGrid.RowsHierarchy.Items.Add method. The 'Add' method returns a HierarchyItem object. This allows you to add sub-items to the HierarchyItem because it has Items.Add method, too.

The code below creates a 2-level Rows Hierarchy and can be used with the VIBlend DataGrid control for Silverlight, WPF and Windows Forms. 

C#

this.DataGrid.RowsHierarchy.CompactStyleRenderingEnabled = false;
for (int i = 0; i < 10; i++)
{
    HierarchyItem row = this.DataGrid.RowsHierarchy.Items.Add("Row" + i);
    HierarchyItem column = this.DataGrid.ColumnsHierarchy.Items.Add("Column" + i);

    for (int j = 0; j < 3; j++)
    {
        HierarchyItem subRow = row.Items.Add("Row" + i + "." + j);
    }
}
  
VB .NET

Me.DataGrid.RowsHierarchy.CompactStyleRenderingEnabled = False
For i As Integer = 0 To 9
    Dim row As HierarchyItem = Me.DataGrid.RowsHierarchy.Items.Add("Row" & i)
    Dim column As HierarchyItem = Me.DataGrid.ColumnsHierarchy.Items.Add("Column" & i)

    For j As Integer = 0 To 2
        Dim subRow As HierarchyItem = row.Items.Add("Row" & i + AscW("." )+ j)
    Next j
Next i

To Fill the DataGrid with data in unbound mode, you should use the DataGrid.CellsArea.SetCellValue method. The method accepts three parameteres - row, column and the cell value.

C#

for (int i = 0; i < 10; i++)
{
    HierarchyItem row = this.DataGrid.RowsHierarchy.Items[i];
    for (int j = 0; j < 10; j++)
    {
        HierarchyItem column = this.DataGrid.ColumnsHierarchy.Items[j];
        this.DataGrid.CellsArea.SetCellValue(row, column, "Cell" + i + "." + j);
        for (int p = 0; p < 3; p++)
        {
            this.DataGrid.CellsArea.SetCellValue(row.Items[p], column, "Cell" + p + "." + j);             
        }
    }
}
       
this.DataGrid.RowsHierarchy.ExpandAllItems();
this.DataGrid.ColumnsHierarchy.ExpandAllItems();
this.DataGrid.RowsHierarchy.AutoResize(AutoResizeMode.FIT_ALL);
this.DataGrid.ColumnsHierarchy.AutoResize(AutoResizeMode.FIT_ALL);
  
VB .NET

For i As Integer = 0 To 9
    Dim row As HierarchyItem = Me.DataGrid.RowsHierarchy.Items(i)
    For j As Integer = 0 To 9
        Dim column As HierarchyItem = Me.DataGrid.ColumnsHierarchy.Items(j)
        Me.DataGrid.CellsArea.SetCellValue(row, column, "Cell" & i + AscW("." )+ j)
        For p As Integer = 0 To 2
            Me.DataGrid.CellsArea.SetCellValue(row.Items(p), column, "Cell" & p + AscW("." )+ j)
        Next p
    Next j
Next i

Me.DataGrid.RowsHierarchy.ExpandAllItems()
Me.DataGrid.ColumnsHierarchy.ExpandAllItems()
Me.DataGrid.RowsHierarchy.AutoResize(AutoResizeMode.FIT_ALL)
Me.DataGrid.ColumnsHierarchy.AutoResize(AutoResizeMode.FIT_ALL)

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.

 

Scrolling Animation in VIBlend Silverlight DataGrid

by viblend 28. November 2010 10:20

The latest version of VIBlend Controls for Silverlight features significant improvements to the DataGrid’s scrolling capabilities.  DataGrid now offers fast animated smooth scrolling with inertia for impressive UI performance.  In this blog post, we will introduce you how to use the properties that you need to know, in order to set up the DataGrid’s scrolling behavior. The ScrollAnimationMode property allows you to enable or disable the animated scrolling. The DataGrid’s default animation mode is scrolling with intertia,  In order to disable the scrolling, you need to set the ScrollAnimationMode property to ScrollAnimationMode.No_Animation.

C#

dataGrid.ScrollAnimationMode = DataGrid.ScrollAnimationModes.NO_ANIMATION;

VB .NET

dataGrid.ScrollAnimationMode = DataGrid.ScrollAnimationModes.NO_ANIMATION

Use the following code snippet to enable the smooth scrolling mode:

C#

dataGrid.ScrollAnimationMode = DataGrid.ScrollAnimationModes.SMOOTH_SCROLL;

VB .NET

dataGrid.ScrollAnimationMode = DataGrid.ScrollAnimationModes.SMOOTH_SCROLL

VIBlend DataGrid control also supports a beautiful opacity animation while you scroll its content. You can enable this animation by using the ScrollOpacityAnimationEnabled property. The code snippet below enables the scrolling opacity animation:

C#

dataGrid.ScrollOpacityAnimationEnabled = true;

VB .NET

dataGrid.ScrollOpacityAnimationEnabled = True

The ScrollAnimationTime property allows you to change the duration of the scrolling animation. Here is demonstrated how to the set the duration to 1 second:

C#

dataGrid.ScrollAnimationTime = new TimeSpan(0, 0, 1);

VB .NET

dataGrid.ScrollAnimationTime = New TimeSpan(0, 0, 1)

By default, when the user drags the thumb on a scrollbar, the content view continuously updates. In deferred scrolling, the content is updated only when the user releases the thumb. You can enable the deferred scrolling mode by using the DeferredScrollingEnabled property.

For example:

C#

dataGrid.DeferredScrollingEnabled = true;

VB .NET

dataGrid.DeferredScrollingEnabled = True

Code reuse in Silverlight, WPF and WinForms DataGrid

by viblend 6. November 2010 02:43

One of our main goals while developing our DataGrid controls for Silverlight, WPF and WinForms was to keep our programming model as similar as possible. The benefit of having a similar programming model is that it enables easy code reuse between multiple platforms and shortens your learning curve.

Going through an Example

Let's consider the sample application shown in Figure 1. The application presents a form with a WinForms DataGrid which is filled with data in unbound mode.


Figure 1

The sample data is shown below:

C#

        string[] firstNames = new string[]
        {
            "Andrew", "Nancy", "Shelley", "Regina", "Yoshi", "Antoni", "Mayumi", "Ian", "Peter", "Lars", "Petra", "Martin", "Sven", "Elio", "Beate", "Cheryl", "Michael", "Guylène"
        };
        string[] lastNames = new string[]
        {
            "Fuller", "Davolio", "Burke", "Murphy", "Nagase", "Saavedra", "Ohno", "Devling", "Wilson", "Peterson", "Winkler", "Bein", "Petersen", "Rossi", "Vileid", "Saylor", "Björn", "Nodier"
        };
        string[] productNames = new string[]
        {
            "Black Tea", "Green Tea", "Doubleshot Espresso", "Caffè Espresso", "Caffè Latte", "White Chocolate Mocha", "Caramel Latte", "Caffè Americano", "Cappuccino", "Espresso Truffle", "Espresso con Panna", "Peppermint Mocha Twist"
        };

VB .NET

        Dim firstNames() As String = { "Andrew", "Nancy", "Shelley", "Regina", "Yoshi", "Antoni", "Mayumi", "Ian", "Peter", "Lars", "Petra", "Martin", "Sven", "Elio", "Beate", "Cheryl", "Michael", "Guylène" }
        Dim lastNames() As String = { "Fuller", "Davolio", "Burke", "Murphy", "Nagase", "Saavedra", "Ohno", "Devling", "Wilson", "Peterson", "Winkler", "Bein", "Petersen", "Rossi", "Vileid", "Saylor", "Björn", "Nodier" }
        Dim productNames() As String = { "Black Tea", "Green Tea", "Doubleshot Espresso", "Caffè Espresso", "Caffè Latte", "White Chocolate Mocha", "Caramel Latte", "Caffè Americano", "Cappuccino", "Espresso Truffle", "Espresso con Panna", "Peppermint Mocha Twist" }

Here is the code that loads the data into the DataGrid control:

C#

        private void LoadData(vDataGridView dataGrid)
        {
           HierarchyItem firstName = dataGrid.ColumnsHierarchy.Items.Add("First Name");
           HierarchyItem lastName = dataGrid.ColumnsHierarchy.Items.Add("Last Name");
           HierarchyItem productName = dataGrid.ColumnsHierarchy.Items.Add("Product");
           HierarchyItem date = dataGrid.ColumnsHierarchy.Items.Add("Date");
           Random random = new Random();

           for (int i = 0; i < 100; i++)
           {
               HierarchyItem row = dataGrid.RowsHierarchy.Items.Add(i.ToString());
               dataGrid.CellsArea.SetCellValue(row, firstName, firstNames[random.Next(0, firstNames.Length - 1)]);
               dataGrid.CellsArea.SetCellValue(row, lastName, lastNames[random.Next(0, lastNames.Length - 1)]);
               dataGrid.CellsArea.SetCellValue(row, productName, productNames[random.Next(0, productNames.Length - 1)]);
               dataGrid.CellsArea.SetCellValue(row, date, DateTime.Now.AddDays(i));
           }

          dataGrid.RowsHierarchy.AutoResize(AutoResizeMode.FIT_ITEM_CONTENT);
          dataGrid.ColumnsHierarchy.AutoResize(AutoResizeMode.FIT_ALL);
       }

VB .NET

        Private Sub LoadData(ByVal dataGrid As vDataGridView)
           Dim firstName As HierarchyItem = dataGrid.ColumnsHierarchy.Items.Add("First Name")
           Dim lastName As HierarchyItem = dataGrid.ColumnsHierarchy.Items.Add("Last Name")
           Dim productName As HierarchyItem = dataGrid.ColumnsHierarchy.Items.Add("Product")
           Dim [date] As HierarchyItem = dataGrid.ColumnsHierarchy.Items.Add("Date")
           Dim random As New Random()

           For i As Integer = 0 To 99
               Dim row As HierarchyItem = dataGrid.RowsHierarchy.Items.Add(i.ToString())
               dataGrid.CellsArea.SetCellValue(row, firstName, firstNames(random.Next(0, firstNames.Length - 1)))
               dataGrid.CellsArea.SetCellValue(row, lastName, lastNames(random.Next(0, lastNames.Length - 1)))
               dataGrid.CellsArea.SetCellValue(row, productName, productNames(random.Next(0, productNames.Length - 1)))
               dataGrid.CellsArea.SetCellValue(row, [date], DateTime.Now.AddDays(i))
           Next i

In the sample code, we have successfully created Rows and Columns in unbound mode and filled the WinForms DataGrid control with data. You will be able to use the same approach for both Silverlight and WPF applications.

A typical Silverlight application is built from a tree of objects where UserControl is the root of the tree. In turn, the UserControl element contains a number of child elements laid out in a variety of ways. The following markup creates a new instance of the VIBlend Silverlight DataGrid:

<UserControl x:Class="SilverlightApplication38.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400" xmlns:viblendDataGrid="clr-namespace:VIBlend.Silverlight.Controls;assembly=VIBlend.Silverlight.DataGrid">
    <Grid x:Name="LayoutRoot" Background="White">
        <viblendDataGrid:DataGrid Height="250" Name="dataGrid1" Width="350" />
    </Grid>
</UserControl>  

It is now time to reuse the code from our Windows Forms application and here is the result:


Figure 2

In order to port the code from the WinForms application to Silverlight and WPF, we need to change only the parameter type of the LoadData method from vDataGridView to DataGrid.

Here is the markup of our WPF application.

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525" xmlns:viblend="clr-namespace:VIBlend.WPF.Controls;assembly=VIBlend.WPF.DataGrid">
    <Grid>
        <viblend:DataGrid Height="250" Name="dataGrid1" Width="450" />
    </Grid>
</Window>

In figure 3 is shown the sample application with our WPF DataGrid.

Figure 3

In summary, with a little effort you can easily create desktop applications with the VIBlend WinForms DataGrid or WPF DataGrid and convert them to Web applications running the Silverlight DataGrid.

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