Click here to Skip to main content
15,883,883 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
See more:
XML
<Window x:Class="WpfApplication5.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300">
    <StackPanel Margin="8">
    <ListView
      Name="listView"
      ItemsSource="{Binding}"
      >
      <ListView.View>
        <GridView>
          <GridViewColumn Header="ID" DisplayMemberBinding="{Binding ID}" />
          <GridViewColumn Header="Name" DisplayMemberBinding="{Binding Name}" />
          <GridViewColumn Header="Balance" Width="140">
            <GridViewColumn.CellTemplate>
              <DataTemplate>
                <CheckBox Tag="{Binding}" Name="Complete" IsThreeState="False" Checked="onButtonClick" />
              </DataTemplate>
            </GridViewColumn.CellTemplate>
          </GridViewColumn>
        </GridView>
      </ListView.View>
    </ListView>
    <Button Margin="4,10">GetAllEvents</Button>
  </StackPanel>
</Window>


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.
Posted
Updated 4-Apr-10 7:56am
v3

Hi,

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); }
        }
        #endregion



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.

Larrythemule
 
Share this answer
 
v3
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:
C#
public bool UseLogonName
        {
            get
            {
                return m_UseLogonName;
            }
            set
            {
                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,
Martin
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900