Click here to Skip to main content
14,635,966 members
Rate this:
Please Sign up or sign in to vote.
See more:
<Window x:Class="WpfApplication5.Window1"



    Title="Window1" Height="300" Width="300">
    <StackPanel Margin="8">



          <GridViewColumn Header="ID" DisplayMemberBinding="{Binding ID}" />
          <GridViewColumn Header="Name" DisplayMemberBinding="{Binding Name}" />
          <GridViewColumn Header="Balance" Width="140">
                <CheckBox Tag="{Binding}" Name="Complete" IsThreeState="False" Checked="onButtonClick" />
    <Button Margin="4,10">GetAllEvents</Button>

i created the data table in .cs file
So i have check box in that data table
if i select that check box i have to select the corresponding row.
Updated 4-Apr-10 7:56am
Rate this:
Please Sign up or sign in to vote.

Solution 2


I think that Martin Smith looks as though he's on the right track.

To satisfy your criteria of selecting the whole row, you might want to create a Dependency Property in your "Code Behind" of type "bool" and bind the "IsChecked" value of your Checkbox and the corresponding row in your data template to that value.

Unless this is due to an unknown constraint I would suggest that you don't use the Checkbox as a three-state checkbox as the third state is null and this might cause problems. I might be wrong on that front though.

#region CheckRow
        /// <summary>
        /// CheckRow Dependency Property
        /// </summary>
        public static readonly DependencyProperty CheckRowProperty =
            DependencyProperty.Register("CheckRow", typeof(bool), typeof(Program),
                new FrameworkPropertyMetadata((bool)false));
        /// <summary>
        /// Gets or sets the CheckRow property. This dependency property
        /// indicates the current state of the checkbox and in turn, the state of the row.
        /// </summary>
        public bool CheckRow
            get { return (bool)GetValue(CheckRowProperty); }
            set { SetValue(CheckRowProperty, value); }

Two things to remember when taking this approach however.

  • The binding in the XAML must be "TwoWay".

  • If your code behind is naive to the class containing the DataTable, you must set the data-context such that it points to where-ever your Dependency property resides.

< CheckBox Margin="10,0,0,0" IsChecked="{Binding Path=CheckRow, Mode="TwoWay"}"/>

The row in the DataTable must also be bound to this value.

I hope this helps.

Rate this:
Please Sign up or sign in to vote.

Solution 1

Hi There,

I'm not 100% sure I have grasped your problem but I think I solved your problem in a previous project of mine.

In your data table (the one held in your .cs file) define a boolean property that will hold the state you wish to display in a checkbox -- I'm assuming you don't need a tri-state binding here (just true/false).

In your xaml create a checkbox and bind the IsChecked property to your data table property. e.g.:

for code:
public bool UseLogonName
                return m_UseLogonName;
                m_UseLogonName = value;

For xaml:
<CheckBox Margin="10,0,0,0" IsChecked="{Binding Path=UseLogonName}">

Remember, you will need to ensure your property correctly raises the PropertyChangeEvent otherwise the binding wont update correctly.

I hope this helps,

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100