How to bind WPF Datagrid radiobutton column to entities class?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • 1 Sparrow
    New Member
    • Nov 2011
    • 5

    How to bind WPF Datagrid radiobutton column to entities class?

    Good morning. I'm Eugene Buzin from Russia.
    In my WPF application I created a LINQ to SQL entities class. Then I created a partial class and there add code to my entity class. Below is the code of it:
    Code:
    namespace Mynamespace
    {
        partial class rts_index
        {
            #region Fields
    
            /// <summary>
            /// Status:
            /// "Selected" - true, "Unselected" - false.
            /// </summary>
            private bool _is_selected;
    
            #endregion
    
            #region Properties
    
            /// <summary>
            /// Get or set the status:
            /// "Selected" - true, "Unselected" - false.
            /// </summary>
            public bool is_selected
            {
                get { return this._is_selected; }
                set { this._is_selected = value; }
            }
    
            #endregion
        }
    }
    Then I executed LINQ to SQL. Works perfectly well. Then I bound WPF Datagrid radiobutton column to is_selected property of the partial class. Below is XAML code:
    Code:
    .
    .
    .
    <Window.Resources>
    <CollectionViewSource x:Key="rts_indexViewSource" d:DesignSource="{d:DesignInstance my:rts_index, CreateList=True}" />
    </Window.Resources>
    .
    .
    .
    <DataGrid Name="dgStockMarketIndex" Grid.Column="1"  Grid.Row="1" AutoGenerateColumns="False"
                      Margin="10" SelectionMode="Extended" CanUserAddRows="False" CanUserDeleteRows="False"
                      CanUserReorderColumns="False" CanUserSortColumns="False" CanUserResizeRows="False"
                      ItemsSource="{Binding Source={StaticResource rts_indexViewSource}}">
                <DataGrid.Columns>
                    <DataGridTemplateColumn Header="Selected">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <RadioButton GroupName="IndexSelection"
                                             IsChecked="{Binding Path=is_selected, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"/>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn
    .
    .
    .
    And here I have the problem. When I'm changing the radiobutton status from Unchecked to Checked it doesn't change the value of is_selected property from false to true in the partial class. I don't know why. Please help me if you can.

    Yours sincerely Eugene Buzin.
  • blackflys
    New Member
    • Aug 2012
    • 1

    #2
    I have exactly the same problem, has somebody found an answer to this? The radio button keeps unchecking when I focus on another line of my datagrid.

    Comment

    Working...