Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# WPF
<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 4-Apr-10 7:30am
Edited 4-Apr-10 8:56am
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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
  Permalink  
v3
Rate this: bad
good
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
        {
            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
  Permalink  

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

  Print Answers RSS
0 Afzaal Ahmad Zeeshan 256
1 OriginalGriff 251
2 BillWoodruff 240
3 Maciej Los 230
4 Sergey Alexandrovich Kryukov 195
0 OriginalGriff 6,419
1 Sergey Alexandrovich Kryukov 6,008
2 DamithSL 5,183
3 Manas Bhardwaj 4,673
4 Maciej Los 4,070


Advertise | Privacy | Mobile
Web01 | 2.8.1411019.1 | Last Updated 2 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

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