data grid and observablecollection RRS feed

  • Question

  • Hi,

    The following sample works ok as is:


    <controls:ChildWindow x:Class="VCI_Envision_Portal.Views.LegacyGraphicDisplay.BackgroundDataxaml"
               Width="400" Height="300" 
               Title="BackgroundDataxaml" xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk">
        <Grid x:Name="LayoutRoot" Margin="2">
                <RowDefinition />
                <RowDefinition Height="Auto" />
            <Button x:Name="CancelButton" Content="Cancel" Click="CancelButton_Click" Width="75" Height="23" HorizontalAlignment="Right" Margin="0,12,0,0" Grid.Row="1" />
            <Button x:Name="OKButton" Content="OK" Click="OKButton_Click" Width="75" Height="23" HorizontalAlignment="Right" Margin="0,12,79,0" Grid.Row="1" />
            <sdk:DataGrid AutoGenerateColumns="True"  Height="226" HorizontalAlignment="Left" Name="BackgroundDataGrid" VerticalAlignment="Top" Width="372" />


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    using System.Collections;
    using System.Collections.ObjectModel;
    using VCI_Envision_Portal.VCIWCFServicesNS;
    namespace VCI_Envision_Portal.Views.LegacyGraphicDisplay
        public partial class BackgroundDataxaml : ChildWindow
            public BackgroundDataxaml()
            private void SetPageValues()
                int index = 0;
                ObservableCollection<Customer> bdd = new ObservableCollection<Customer>();
                int iCount = LegacyGraphicDisplay.vci_pt_data_cooked.Count();
                while (index < iCount)
                    int iColumnCount = 0;
                    if (LegacyGraphicDisplay.vci_pt_data_cooked[index] != null)
                        int iColumns = LegacyGraphicDisplay.vci_pt_data_cooked[index].Count();
                        while (iColumnCount < iColumns)
                            Customer bob = new Customer();
                            bob.FirstName = LegacyGraphicDisplay.vci_pt_data_cooked[index][iColumnCount].Pt_Column;
                            bob.LastName = LegacyGraphicDisplay.vci_pt_data_cooked[index][iColumnCount].Pt_Value;
                            bdd.Add( bob );
                BackgroundDataGrid.ItemsSource = bdd;
            private void OKButton_Click(object sender, RoutedEventArgs e)
                this.DialogResult = true;
            private void CancelButton_Click(object sender, RoutedEventArgs e)
                this.DialogResult = false;
        public class Customer 
            public string FirstName { get; set; } 
            public string LastName { get; set; } 

    Thing is it creates a single very long list of firstname/lastname

    the list is created from a two dimension array of x indexes and y columns per index.

    So how can I get the observablecollection + datagrid to present the <firstname/lastname > pairs within a two dimensional array.

    For instance employee first/last name pairs listed per department.



    Wednesday, June 19, 2013 9:24 PM

All replies

  • Hi boyd1,

    As per your explanation you are displaying first name in one column and last name in another column of a grid.

    But you didnt explain your requirement properly, give more so that we can understand your issue.

    Thanks & Regards
    Syed Amjad Sr. Silverlight/WPF Developer,
    yahoo : syedamjad6736@yahoo.com, skype : syedamjad.0786.
    Please use Marked as Answer if my post solved your problem and use Vote As Helpful if a post was useful.

    Wednesday, August 5, 2015 10:36 AM