entity-frameworkdatagridsilverlight-4.0checkboxdomaindatasource

SilverLight 4.0 C# - DomainDataSource DataGrid with CheckBox Column (UI only - not a data field) to allow user to select multiple records/rows


New to SilverLight and to posting here. Please have mercy and be specific :)

Using RIA services with DomainDataSource and DataGrid control to display data rows from SQL server query

Goal: Have checkbox column (UI only - not a data field) to allow user to select multiple records/rows

BackGround:
1) Created new SilverLight 4, C# solution with RIA services

2) in ProjectName.Web

3) in SilverLightProjectName

4) in MainPage.XAML added checkbox column

What's Happening: checkboxes are selected/checked by user, scroll down, scroll back up, all checkboxes reset and ONLY Datagrid.SelectedItem is still checked. I have read this behavior is 'by design' due to paging.

<sdk:DataGrid  RowStyle="{StaticResource newDataGridStyle}"  AutoGenerateColumns="False" ItemsSource="{Binding ElementName=ddsPagerApp, Path=Data}" Name="vwPagerAppDataGrid" RowDetailsVisibilityMode="VisibleWhenSelected" MouseLeftButtonDown="vwPagerAppDataGrid_MouseLeftButtonDown" VerticalGridLinesBrush="#FFB9B9B9" FontSize="10" Grid.Row="3" SelectionChanged="vwPagerAppDataGrid_SelectionChanged" KeyDown="vwPagerAppDataGrid_KeyDown" MouseLeftButtonUp="vwPagerAppDataGrid_MouseLeftButtonUp" MouseRightButtonUp="vwPagerAppDataGrid_MouseRightButtonUp" DataContext="{Binding}" SelectionMode="Single" IsEnabled="True" IsReadOnly="False" TabIndex="2" Grid.Column="1" Margin="0,10,9,9">
        <sdk:DataGrid.Columns>                
            <sdk:DataGridTemplateColumn IsReadOnly="False">                    
                <sdk:DataGridTemplateColumn.CellEditingTemplate>
                    <DataTemplate>
                        <CheckBox  Name="ChkSelected" IsThreeState="False" IsChecked="{Binding Path=IsChecked, Mode=TwoWay}" HorizontalAlignment="Center" VerticalAlignment="Center" Unchecked="IndividualCheckBox_Unchecked" Checked="IndividualCheckBox_Checked" Width="Auto" Height="Auto" />
                    </DataTemplate>
                </sdk:DataGridTemplateColumn.CellEditingTemplate>
            </sdk:DataGridTemplateColumn>
        <sdk:DataGridTextColumn x:Name="fullNameColumn" Binding="{Binding Path=FullName}" Header="Full Name" IsReadOnly="True" />
        <sdk:DataGridTextColumn x:Name="departmentColumn" Binding="{Binding Path=department}" Header="Department" IsReadOnly="True" />
        <sdk:DataGridTextColumn x:Name="pager_number_displayColumn" Binding="{Binding Path=pager_number_display}" Header="Pager Number" IsReadOnly="True" />
        <sdk:DataGridTextColumn x:Name="PageTo" Binding="{Binding Path=PageTo}" Header="Page To" IsReadOnly="True" />
    </sdk:DataGrid.Columns>
</sdk:DataGrid>
<riaControls:DomainDataSource AutoLoad="True" d:DesignData="{d:DesignInstance my:vwPagerApp, CreateList=true}" Height="0" LoadedData="ddsPagerApp_LoadedData" Name="ddsPagerApp" QueryName="GetVwPagerAppsQuery" Width="0" Margin="10,0,25,45" Background="#FF7D0000" Foreground="#FF7D0000" Visibility="Visible">
    <riaControls:DomainDataSource.DomainContext>
        <my:NotifyDomainContext />
    </riaControls:DomainDataSource.DomainContext>
</riaControls:DomainDataSource>

Attempt 1:

Getting error: Error 11009: Property ' ' is not mapped

UPDATE: Reversed Attempt 1:

Attempt 2:
Researching possibility of defining a partial class for the entity, wiring to DataGrid, and using that to track CheckBox values. Any advice on if this will work/how to?

Trying my best to absorb this. Please enlighten me...and thank you in advance :)


Solution

  • This is what I implemented and it worked beautifully. I hope it helps someone else in the future :)

    1) SilverLight Project C#: Extend entity class using partial class (in separate file, but within same namespace – compiles into 1 class but keeps generated code separate)

    namespace Pager.Web
    {
      public partial class pager_grp
        {
            bool _IsChecked = false;
            public bool IsChecked
            {
                get
                {return this._IsChecked;}
                set
                {this._IsChecked = !IsChecked;}
            }
        }
    }
    

    2) SilverLight Project GUI: Create Column in DataGrid of type DataGridTemplateColumn named chkSelected

    3) SilverLight Project XAML: use template and bind to new property declared in partial class

       <sdk:DataGridTemplateColumn IsReadOnly="False">                    
       <sdk:DataGridTemplateColumn.CellEditingTemplate>
            <DataTemplate>
                <CheckBox  Name="ChkSelected" IsThreeState="False" IsChecked="{Binding    Path=IsChecked, Mode=TwoWay}" HorizontalAlignment="Center" VerticalAlignment="Center" Unchecked="IndividualCheckBox_Unchecked" Checked="IndividualCheckBox_Checked" Width="Auto" Height="Auto" />
            </DataTemplate>
        </sdk:DataGridTemplateColumn.CellEditingTemplate>
    </sdk:DataGridTemplateColumn>