none
collectionViewSource Listview

    Question

  • I have a listview which I bind it using datacontext. I am using a WCF service to get the results in the datatable and then binding it to the grid.
    Listview.datacontext=Display_Records ' where Display_Records is the datatable returned.

    Now I need to group the column in the listview. I found out that using collectionViewSource is a best bet to use.
    I need my listview to look similar to this one: http://blogs.msdn.com/atc_avalon_team/archive/2006/03/15/551721.aspx

    My question is how can I bind datasource to the collectionviewsource.Please find my xaml and VB.net code attached.

    <Page x:Class="EmployeeInfoRequest"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"
        xmlns:dat="clr-namespace:System.Windows.Data;assembly=PresentationFramework"   
        Title="EmployeeInfoRequest" WindowTitle="EMT Contacts - " Loaded="Page_Loaded">
        <Page.Resources>
           <DataTemplate x:Key="FirstCell">
                <StackPanel Orientation="Horizontal">
                    <CheckBox x:Name="chk1" FontSize="16" Foreground="DarkBlue" IsChecked="{Binding Path=IsSelected, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListViewItem}}}"/>
                </StackPanel>
            </DataTemplate>
    
            <Style x:Key="myHeaderStyle" TargetType="{x:Type GridViewColumnHeader}">
                <Setter Property="Background" Value="CadetBlue"/> 
                <Setter Property="FontSize" Value="13"/>
            </Style>
    
    
            <Style x:Key="CustomListViewItemStyle" TargetType="{x:Type ListViewItem}">
                <Setter Property="SnapsToDevicePixels" Value="true"/>
                <Setter Property="OverridesDefaultStyle" Value="true"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="ListViewItem">
                            
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
    
    
                <Style.Triggers>
                    <Trigger Property="ItemsControl.AlternationIndex" Value="0">
                        <Setter Property="Background" Value="Beige"></Setter>
                        <Setter Property="FontSize" Value="13"></Setter>
                        <Setter Property="Height" Value="20"></Setter>
                        <!--<Setter Property="HorizontalContentAlignment" Value="Center"></Setter>-->
                    </Trigger>
                    <Trigger Property="ItemsControl.AlternationIndex" Value="1">
                        <Setter Property="Background" Value="LightBlue"></Setter>
                        <Setter Property="FontSize" Value="13"></Setter>
                        <Setter Property="Height" Value="20"></Setter>
                        <!--<Setter Property="HorizontalContentAlignment" Value="Center"></Setter>-->
                    </Trigger>
                </Style.Triggers>
            </Style>
    
            <CollectionViewSource x:Key='src' 
                              Source="{Binding Source={StaticResource MyData},XPath=Item}">
                <CollectionViewSource.GroupDescriptions>
                    <PropertyGroupDescription PropertyName="@Column1" />
                </CollectionViewSource.GroupDescriptions>
            </CollectionViewSource>
    
        </Page.Resources>
        <ScrollViewer Name="ScrollViewer1" VerticalAlignment="Stretch">
    
            <StackPanel Name="StackPanel1" Width="900" >
                <Border>
                    <Grid>
                        <Image Source="awgelogo.gif" Width="50" Height="45" HorizontalAlignment="Left" Margin="17,10,0,10" Name="Image1" Stretch="Fill" />
                        <Label FontSize="18" Foreground="Black" Margin="78,8,270,0" FontWeight="Bold">Alliance Engineering, Inc</Label>
                        <Label FontSize="13" Foreground="Black" Margin="78,30,270,0">A Wood Group Company</Label>
                    </Grid>
                </Border>
                <Border BorderBrush="Black" BorderThickness="0,2,0,2">
                    <Label Name="lbl_Header2" VerticalAlignment="Center" FontSize="13" FontWeight="Bold" Foreground="Black">Employee Emergency Contact Information</Label>
                </Border>
                <StackPanel Name="Stack_Top_Buttons" HorizontalAlignment="Center" Orientation="Horizontal">
                    <Button Name="cmd_Export1"             Style="{DynamicResource Gel_Button_Template}" Margin="9" FontSize="9" FontWeight="SemiBold" Foreground="Yellow" Background="Purple" BorderBrush="Magenta"        Height="20" HorizontalAlignment="Center" Width="90" Click="cmd_Export_Click" ToolTip="Exports data.">Export</Button>
                    <Button Name="cmd_Notify1"             Style="{DynamicResource Gel_Button_Template}" Margin="9" FontSize="9" FontWeight="SemiBold" Foreground="Yellow" Background="RoyalBlue" BorderBrush="DeepSkyBlue"        Height="20" HorizontalAlignment="Center" Width="90" Click="cmd_Notify_Click" ToolTip="Notify only checked users.">Notify All</Button>
                    <Button Name="cmd_NotifyAll1"             Style="{DynamicResource Gel_Button_Template}" Margin="9" FontSize="9" FontWeight="SemiBold" Foreground="Yellow" Background="Peru" BorderBrush="PaleTurquoise"     Height="20" HorizontalAlignment="Center" Width="90" Click="cmd_NotifyAll_Click" ToolTip="Notify All users.">Notify</Button>
                    <Button Name="cmd_Return_to_Main1"     Style="{DynamicResource Gel_Button_Template}" Margin="9" FontSize="9" FontWeight="SemiBold" Foreground="Yellow" Background="LightGray" BorderBrush="LightCyan"   Height="20" HorizontalAlignment="Center" Width="90" Click="cmd_RtrFrmEmplInfoRqt_Click" ToolTip="Return to the main menu without further action">Return</Button>
                </StackPanel>
    
                <Border Name="bdr_Body" BorderThickness="1" CornerRadius="15" Height="500">
                    <StackPanel Orientation="vertical">
                        <Border Name="Border1" Margin="35,13,43.09,0" BorderThickness="1" BorderBrush="Black" Height="80" VerticalAlignment="Top" CornerRadius="15" Background="WhiteSmoke">
                            <Grid Name="grd_Employee_Info">
                                <TextBlock Name="TextBlock2" FontWeight="Bold" FontSize="13" Margin="10.908,6,0,0" Text="Supervisor:" HorizontalAlignment="Left" Width="81.91" Height="21" VerticalAlignment="Top" />
                                <TextBlock Name="txtb_SupervisorName" FontSize="13" Margin="0,6,581.468,0" Text="Bill, The Supervisor" HorizontalAlignment="Right" Width="123.442" Height="15" VerticalAlignment="Top" />
                                <TextBlock Name="TextBlock3" FontWeight="Bold"  FontSize="13" Margin="10.818,31,0,32" Text="Department:" HorizontalAlignment="Left" Width="82" />
                                <!--<TextBlock Name="txtb_Department" FontSize="13" Margin="113,29,334,34" Text="IT" />-->
                                <ComboBox Name="cbo_Department" ItemsSource="{Binding}" FontSize="13" Margin="0,29,555.91,34" HorizontalAlignment="Right" Width="149" />
                                 <TextBlock Name="txtb4" FontWeight="Bold"  FontSize="13" Margin="10.818,0,0,13" Text="Go Level:" HorizontalAlignment="Left" Width="82" Height="15" VerticalAlignment="Bottom" />
                                 <ComboBox Name="cbo_Level" FontSize="13" Margin="113,0,0,10" HorizontalAlignment="Left" Width="100" Height="15" VerticalAlignment="Bottom">
                                     <ComboBoxItem>Direct Reports</ComboBoxItem> 
                                     <ComboBoxItem>1</ComboBoxItem>    
                                     <ComboBoxItem>2</ComboBoxItem>
                                 </ComboBox>
                              </Grid>
                        </Border>
                        <Border Name="Border2" Margin="35,13,43.09,0" BorderThickness="1" BorderBrush="Black" Height="Auto"  Width="Auto" VerticalAlignment="Top" >
                            <ListView Name="grd_Emp_Summary" ItemsSource="{Binding}"  AlternationCount="2" Width="Auto" Height="Auto" >
                            <ListView.View>
                                    <GridView>
                                        <GridView.Columns>
                                            <GridViewColumn Header="Notify" HeaderContainerStyle="{StaticResource myHeaderStyle}" CellTemplate="{StaticResource FirstCell}"/>
                                            <GridViewColumn Header="Staff Member" HeaderContainerStyle="{StaticResource myHeaderStyle}" DisplayMemberBinding="{Binding Path=EMPL_Name}"/>
                                            <GridViewColumn Header="Date Updated" HeaderContainerStyle="{StaticResource myHeaderStyle}" DisplayMemberBinding="{Binding Path=Date_Updated}"/>
                                            <GridViewColumn Header="No of fields completed" HeaderContainerStyle="{StaticResource myHeaderStyle}" DisplayMemberBinding="{Binding Path=Completion_Count}"/>
                                        </GridView.Columns>
                                    </GridView>
                                </ListView.View>
                            </ListView>
                        </Border>
                        <Border Name="Border3" Margin="35,13,43.09,0" BorderThickness="1" BorderBrush="Black" Height="372"  Width="826" VerticalAlignment="Top" >
                            <ListView Name="grd_Emp_Summary_Level1" ItemsSource="{Binding Source={StaticResource src}}"  AlternationCount="2" Width="Auto" Height="372" >
                                <ListView.GroupStyle>
                                    <GroupStyle>
                                        <GroupStyle.ContainerStyle>
                                            <Style TargetType="{x:Type GroupItem}">
                                                <Setter Property="Margin" Value="0,0,0,5"/>
                                                <Setter Property="Template">
                                                    <Setter.Value>
                                                        <ControlTemplate TargetType="{x:Type GroupItem}">
                                                            <Expander IsExpanded="True" BorderBrush="#FFA4B97F" BorderThickness="0,0,0,1">
                                                                <Expander.Header>
                                                                    <DockPanel>
                                                                        <TextBlock FontWeight="Bold" Text="{Binding Path=EMPL_Name}" Margin="5,0,0,0" Width="100"/>
                                                                        <TextBlock FontWeight="Bold" Text="{Binding Path=ItemCount}"/>
                                                                    </DockPanel>
                                                                </Expander.Header>
                                                                <Expander.Content>
                                                                    <ItemsPresenter />
                                                                </Expander.Content>
                                                            </Expander>
                                                        </ControlTemplate>
                                                    </Setter.Value>
                                                </Setter>
                                            </Style>
                                        </GroupStyle.ContainerStyle>
                                    </GroupStyle>
                                </ListView.GroupStyle>
    
                                <ListView.View>
                                    <GridView>
                                        <GridView.Columns>
                                            <GridViewColumn Header="Notify" HeaderContainerStyle="{StaticResource myHeaderStyle}" CellTemplate="{StaticResource FirstCell}"/>
                                            <GridViewColumn Header="Manager" HeaderContainerStyle="{StaticResource myHeaderStyle}" DisplayMemberBinding="{Binding Path=Column1}"/>
                                            <GridViewColumn Header="Staff Member" HeaderContainerStyle="{StaticResource myHeaderStyle}" DisplayMemberBinding="{Binding Path=EMPL_Name}"/>
                                            <GridViewColumn Header="Date Updated" HeaderContainerStyle="{StaticResource myHeaderStyle}" DisplayMemberBinding="{Binding Path=Date_Updated}"/>
                                            <GridViewColumn Header="No of fields completed" HeaderContainerStyle="{StaticResource myHeaderStyle}" DisplayMemberBinding="{Binding Path=Completion_Count}"/>
                                        </GridView.Columns>
                                    </GridView>
                                </ListView.View>
                            </ListView>
                           
                        </Border>
                    </StackPanel>
    
                </Border>
                <StackPanel Name="Stack_Bottom_Buttons" HorizontalAlignment="Center" Orientation="Horizontal">
                    <Button Name="cmd_Export2"             Style="{DynamicResource Gel_Button_Template}" Margin="9" FontSize="9" FontWeight="SemiBold" Foreground="Yellow" Background="Purple" BorderBrush="Magenta"        Height="20" HorizontalAlignment="Center" Width="90" Click="cmd_Export_Click" ToolTip="Exports data.">Export</Button>
                    <Button Name="cmd_Notify2"             Style="{DynamicResource Gel_Button_Template}" Margin="9" FontSize="9" FontWeight="SemiBold" Foreground="Yellow" Background="RoyalBlue" BorderBrush="DeepSkyBlue"        Height="20" HorizontalAlignment="Center" Width="90" Click="cmd_Notify_Click" ToolTip="Notify only checked users.">Notify All</Button>
                    <Button Name="cmd_NotifyAll2"             Style="{DynamicResource Gel_Button_Template}" Margin="9" FontSize="9" FontWeight="SemiBold" Foreground="Yellow" Background="Peru" BorderBrush="PaleTurquoise"     Height="20" HorizontalAlignment="Center" Width="90" Click="cmd_NotifyAll_Click" ToolTip="Notify All users.">Notify</Button>
                    <Button Name="cmd_Return_to_Main2"     Style="{DynamicResource Gel_Button_Template}" Margin="9" FontSize="9" FontWeight="SemiBold" Foreground="Yellow" Background="LightGray" BorderBrush="LightCyan"   Height="20" HorizontalAlignment="Center" Width="90" Click="cmd_RtrFrmEmplInfoRqt_Click" ToolTip="Return to the main menu without further action">Return</Button>
                </StackPanel>
            </StackPanel>
    
        </ScrollViewer>
    </Page>
    VB.NET Code is as follows:
    Private Sub Bind_Grid_Level1()
    
            Try
    
                Dim Client As New AEDEV_EMT_WCF.AEDEV_Service_EMT_RequestClient
                'DataTable for Manager's Subordinates
                Dim Display_Records As New DataTable
    
                'Datatable to get employee's emergency details
                Dim Details_Table As New DataTable
    
                'Get all the subordinates for the Supervisor.
                Display_Records = Client.Get_Costpoint_Subordinates1(MGR_ID)
    
                'Close Client
                Client.Close()
    
                'Bind the Listview
                grd_Emp_Summary_Level1.DataContext = Display_Records
    
    
            Catch ex As Exception
                Beep()
                MsgBox(ex.Message)
            End Try
    
        End Sub










    Tuesday, June 02, 2009 10:49 PM

Answers

  • Since you look new to the forums, one piece of advice, if you don't mind. Typically people tend to ignore the posts which has lots of code. Instead paste only that code which is of problem to you and if required, we would ask you post more details. Most of the folks here are pretty smart and understand what your problem is, most of the times.  This way, more users would concentrate on your issue instead of bouncing it off.

    As of your question...

    <CollectionViewSource Source={Binding SourceOfData}>
    ....
    </CollectionViewSource>


    And you have to set the DataContext of any parent control (in your case, the Page) to the object which has the property "SourceOfData". Thats the usual way...

    For your case, try this...

    <CollectionViewSource Source={Binding}>
    ...
    </....>

    in this case, set this.DataContext to your data table.
    Software Engineer 1, http://krishnabhargav.blogspot.com
    Tuesday, June 02, 2009 11:04 PM
  • Manju,
    First I would remove the grouping altogether (from CollectionViewSource and ListView itself) to see if the ListView even populates. I have not set-up the ListView this way through the MVVM by setting the context to a DataTable so not sure how this would behave the way you have it.
    Second the expander header, in the DockPanel, the Binding Path should be "Name" for all grouping names. "Name" is used by GroupDescription for the property it is grouping by and specifying the actual Property is not correct.

    I also bind in the code behind which is easier for me as follows:

    CollectionViewSource myCollectionViewSource = new CollectionViewSource();
    myCollectionViewSource.Source = Display_Records;
    myCollectionViewSource.GroupDescriptions.Add(new PropertyGroupDescription("Column1"));
    Binding myBinding = new Binding();
    myBinding.Source = myCollectionViewSource;
    BindingOperations.SetBinding(grd_Emp_Summary_Level1, ListView.ItemsSourceProperty, myBinding );
    I am assuming that the DataTable binding works same as ObservableCollection that I use (I have not tested this with DataTable). Also You need the correct PropertyName for Grouping, if it is "Emp_Name" then use that.

    I am not sure if I helped any but firs tstep is to see the rows, don't worry about grouping or GridView yet, just see it in a plain ListView to make sure you are binding correctly.


    noorbakhsh
    Wednesday, June 03, 2009 11:44 PM

All replies

  • Since you look new to the forums, one piece of advice, if you don't mind. Typically people tend to ignore the posts which has lots of code. Instead paste only that code which is of problem to you and if required, we would ask you post more details. Most of the folks here are pretty smart and understand what your problem is, most of the times.  This way, more users would concentrate on your issue instead of bouncing it off.

    As of your question...

    <CollectionViewSource Source={Binding SourceOfData}>
    ....
    </CollectionViewSource>


    And you have to set the DataContext of any parent control (in your case, the Page) to the object which has the property "SourceOfData". Thats the usual way...

    For your case, try this...

    <CollectionViewSource Source={Binding}>
    ...
    </....>

    in this case, set this.DataContext to your data table.
    Software Engineer 1, http://krishnabhargav.blogspot.com
    Tuesday, June 02, 2009 11:04 PM
  • ohh okie.Will keep in mind about not  posting too much of code in my next post.

    Coming back to my issue: I tried with what you mentioned, but still I happen to get blank listview. I can see records in my datatable.I think I am missing something. can you please clarify this statement of yours "in this case, set this.DataContext to your data table. " ? Do you have any sample with my requirement ? Thanks
    <CollectionViewSource x:Key='src' Source="{Binding}">
                <CollectionViewSource.GroupDescriptions>
                    <PropertyGroupDescription PropertyName="Column1" />
                </CollectionViewSource.GroupDescriptions>
            </CollectionViewSource>
    <ListView Name="grd_Emp_Summary_Level1" ItemsSource="{Binding Source={StaticResource src}}"  AlternationCount="2" Height="250"  Width="Auto" >
                                <ListView.GroupStyle>
                                    <GroupStyle>
                                        <GroupStyle.ContainerStyle>
                                            <Style TargetType="{x:Type GroupItem}">
                                                <Setter Property="Margin" Value="0,0,0,5"/>
                                                <Setter Property="Template">
                                                    <Setter.Value>
                                                        <ControlTemplate TargetType="{x:Type GroupItem}">
                                                               <Expander IsExpanded="True" BorderBrush="#FFA4B97F" BorderThickness="0,0,0,1">
                                                                <Expander.Header>
                                                                    <DockPanel>
                                                                        <TextBlock FontWeight="Bold" Text="{Binding Path=EMPL_Name}" Margin="5,0,0,0" Width="100"/>
                                                                        <TextBlock FontWeight="Bold" Text="{Binding Path=ItemCount}"/>
                                                                    </DockPanel>
                                                                </Expander.Header>
                                                                <Expander.Content>
                                                                    <ItemsPresenter />
                                                                </Expander.Content>
                                                            </Expander>
                                                        </ControlTemplate>
                                                    </Setter.Value>
                                                </Setter>
                                            </Style>
                                        </GroupStyle.ContainerStyle>
                                    </GroupStyle>
                                </ListView.GroupStyle>
                                <ListView.View>
    <GridView>
                                        <GridView.Columns>
                                            <GridViewColumn Header="Notify" HeaderContainerStyle="{StaticResource myHeaderStyle}" CellTemplate="{StaticResource FirstCell}"/>
                                         <GridViewColumn Header="Staff Member" HeaderContainerStyle="{StaticResource myHeaderStyle}" DisplayMemberBinding="{Binding Path=EMPL_Name}"/>
                                            <GridViewColumn Header="Date Updated" HeaderContainerStyle="{StaticResource myHeaderStyle}" DisplayMemberBinding="{Binding Path=Date_Updated}"/>
                                            <GridViewColumn Header="No of fields completed" HeaderContainerStyle="{StaticResource myHeaderStyle}" DisplayMemberBinding="{Binding Path=Completion_Count}"/>
                                        </GridView.Columns>
                                    </GridView>
                                </ListView.View>

    Wednesday, June 03, 2009 8:46 PM
  • Manju,
    First I would remove the grouping altogether (from CollectionViewSource and ListView itself) to see if the ListView even populates. I have not set-up the ListView this way through the MVVM by setting the context to a DataTable so not sure how this would behave the way you have it.
    Second the expander header, in the DockPanel, the Binding Path should be "Name" for all grouping names. "Name" is used by GroupDescription for the property it is grouping by and specifying the actual Property is not correct.

    I also bind in the code behind which is easier for me as follows:

    CollectionViewSource myCollectionViewSource = new CollectionViewSource();
    myCollectionViewSource.Source = Display_Records;
    myCollectionViewSource.GroupDescriptions.Add(new PropertyGroupDescription("Column1"));
    Binding myBinding = new Binding();
    myBinding.Source = myCollectionViewSource;
    BindingOperations.SetBinding(grd_Emp_Summary_Level1, ListView.ItemsSourceProperty, myBinding );
    I am assuming that the DataTable binding works same as ObservableCollection that I use (I have not tested this with DataTable). Also You need the correct PropertyName for Grouping, if it is "Emp_Name" then use that.

    I am not sure if I helped any but firs tstep is to see the rows, don't worry about grouping or GridView yet, just see it in a plain ListView to make sure you are binding correctly.


    noorbakhsh
    Wednesday, June 03, 2009 11:44 PM
  • Noorbakhsh,
    Firstly thanks for the prompt reply. I tried like what you suggested, but I get a blank listview.Kindly see my code below:

    xaml:

     <Page.Resources>
      <CollectionViewSource x:Key='src' Source="{Binding}">
                <!--<CollectionViewSource.GroupDescriptions>
                    <PropertyGroupDescription PropertyName="Column1" />
                </CollectionViewSource.GroupDescriptions>-->
            </CollectionViewSource>
     </Page.Resources>
    
    <ListView Name="grd_Emp_Summary_Level1" ItemsSource="{Binding Source={StaticResource src}}" AlternationCount="2" Height="250"  Width="Auto" >
                                <ListView.GroupStyle>
                                    <GroupStyle>
                                        <GroupStyle.ContainerStyle>
                                            <Style TargetType="{x:Type GroupItem}">
                                                <Setter Property="Margin" Value="0,0,0,5"/>
                                                <Setter Property="Template">
                                                    <Setter.Value>
                                                        <ControlTemplate TargetType="{x:Type GroupItem}">
                                                               <Expander IsExpanded="True" BorderBrush="#FFA4B97F" BorderThickness="0,0,0,1">
                                                                <Expander.Header>
                                                                    <DockPanel>
                                                                        <TextBlock FontWeight="Bold" Text="{Binding Path=Name}" Margin="5,0,0,0" Width="100"/>
                                                                        <TextBlock FontWeight="Bold" Text="{Binding Path=ItemCount}"/>
                                                                    </DockPanel>
                                                                </Expander.Header>
                                                                <Expander.Content>
                                                                    <ItemsPresenter />
                                                                </Expander.Content>
                                                            </Expander>
                                                        </ControlTemplate>
                                                    </Setter.Value>
                                                </Setter>
                                            </Style>
                                        </GroupStyle.ContainerStyle>
                                    </GroupStyle>
                                </ListView.GroupStyle>
                                <ListView.View>
                                    <GridView>
                                        <GridView.Columns>
                                            <GridViewColumn Header="Notify" HeaderContainerStyle="{StaticResource myHeaderStyle}" CellTemplate="{StaticResource FirstCell}"/>
                                            <!--<GridViewColumn Header="Manager" HeaderContainerStyle="{StaticResource myHeaderStyle}" DisplayMemberBinding="{Binding Path=Column1}"/>-->
                                            <GridViewColumn Header="Staff Member" HeaderContainerStyle="{StaticResource myHeaderStyle}" DisplayMemberBinding="{Binding Path=EMPL_Name}"/>
                                            <GridViewColumn Header="Date Updated" HeaderContainerStyle="{StaticResource myHeaderStyle}" DisplayMemberBinding="{Binding Path=Date_Updated}"/>
                                            <GridViewColumn Header="No of fields completed" HeaderContainerStyle="{StaticResource myHeaderStyle}" DisplayMemberBinding="{Binding Path=Completion_Count}"/>
                                        </GridView.Columns>
                                    </GridView>
                                </ListView.View>
                            </ListView>
    CollectionViewSource Class

    Public Class CollectionViewSource
            Inherits DependencyObject
            Implements ISupportInitialize, IWeakEventListener
            Private _Source As Object
            Public Property Source() As Object
                Get
                    Return _Source
                End Get
                Set(ByVal value As Object)
                    _Source = value
                End Set
            End Property
    
            Public Function ReceiveWeakEvent(ByVal managerType As System.Type, ByVal sender As Object, ByVal e As System.EventArgs) As Boolean Implements System.Windows.IWeakEventListener.ReceiveWeakEvent
    
            End Function
    
            Public Sub BeginInit() Implements System.ComponentModel.ISupportInitialize.BeginInit
    
            End Sub
    
            Public Sub EndInit() Implements System.ComponentModel.ISupportInitialize.EndInit
    
            End Sub
        End Class


    Code Behind Vb.NET

    Private Sub Bind_Grid_Level1()
    
            Try
    
                Dim Client As New AEDEV_EMT_WCF.AEDEV_Service_EMT_RequestClient
                'DataTable for Manager's Subordinates
                Dim Show_Records As New DataTable
    
                'Datatable to get employee's emergency details
                Dim Details_Table As New DataTable
    
                'Get all the subordinates for the Supervisor.
                Show_Records = Client.Get_Costpoint_Subordinates1(MGR_ID)
    
                'Add updated column to the Display_Table datatable.
                Show_Records.Columns.Add("Date_Updated")
                Show_Records.Columns.Add("Completion_Count")
                Show_Records.Columns.Add("Manager")
    
                'Close Client
                Client.Close()
    
                'Dim cvs As CollectionViewSource = New CollectionViewSource()
                mycollectionViewSource = New CollectionViewSource
                mycollectionViewSource.Source = Display_Records
                'grd_Emp_Summary_Level1.DataContext = mycollectionViewSource
                Dim myBinding As New Binding
                myBinding.Source = mycollectionViewSource
                BindingOperations.SetBinding(grd_Emp_Summary_Level1, ListView.ItemsSourceProperty, myBinding)
        
    
            Catch ex As Exception
                Beep()
                MsgBox(ex.Message)
            End Try
    Thanks
    - m
    Thursday, June 04, 2009 4:51 PM
  • Yes I do get to see records in the Listview if I remove grouping and collectionviewsource code from xaml. I think I am setting the collectionviewsource binding source correctly in xaml, hence the issue.

    Thursday, June 04, 2009 7:20 PM
  • Manju,
    Your GroupStyle looks good, you are using Column1 for manager, so that looks good too. If you are getting data in the ListView, I am not sure why you can not group it with what you have since you have a CollectionViewSource also. It all looks like it should work.
    noorbakhsh
    Thursday, June 04, 2009 8:22 PM
  • What do u put in your xaml for collectionviewsource Source Property ? and in the Listview ItemSource in xaml ?
     <CollectionViewSource x:Key='src' Source="????????????????????????????">
                <!--<CollectionViewSource.GroupDescriptions>
                    <PropertyGroupDescription PropertyName="Column1" />
                </CollectionViewSource.GroupDescriptions>-->
     </CollectionViewSource>
    Thursday, June 04, 2009 8:55 PM
  • Manju,
    I have an ObservableCollection<myObjects> as I have not work with DataTables or the MVVM and DataContext in this situation.
    noorbakhsh
    Friday, June 05, 2009 6:21 PM
  • Try looking at what Bea Stollnitz has to say about CollectionViewSource DataTable.
    http://www.beacosta.com/blog/?m=200701
    Software Engineer 1, My Blog
    Friday, June 05, 2009 8:10 PM
  • hey Noorbaksh,

    Well now I am trying to bind it through Observable Collection.I come up with another problem now.
    Kindly see my post http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/75122e56-23ef-43bf-814e-8f11ea7a9e02/

    Thanks
    Thursday, June 11, 2009 10:20 PM