Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8685815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:40:20+00:00 2026-06-12T22:40:20+00:00

I have this XAML <DataGrid Name=grdData … > <DataGrid.Columns> <DataGridTemplateColumn Header=Something> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <CheckBox

  • 0

I have this XAML

<DataGrid Name="grdData" ... >
   <DataGrid.Columns>
      <DataGridTemplateColumn Header="Something">
         <DataGridTemplateColumn.CellTemplate>
            <DataTemplate>
               <CheckBox Name="chb" />
            </DataTemplate>
         </DataGridTemplateColumn.CellTemplate>
       </DataGridTemplateColumn>
    </DataGrid.Columns>
</DataGrid>

i try this code to get Checked State

for( int i = 0 ; i < grdData.Items.Count ; i++ )
{
    DataGridRow row = ( DataGridRow )grdData.ItemContainerGenerator.ContainerFromIndex( i );
    var cellContent = grdData.Columns[ 1 ].GetCellContent( row ) as CheckBox;
    if( cellContent != null && cellContent.IsChecked == true )
    {
       //some code
    }
}

my code is wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T22:40:22+00:00Added an answer on June 12, 2026 at 10:40 pm

    Since you are looping over the Items collection which is your ItemsSource. Why not to have the bool property in your class itself and get it from there itself.

    Say if ItemSource is List<Person>, then create a bool property say IsManager in class Person and bind it with your checkBox like this –

    <CheckBox IsChecked="{Binding IsManager}"/>
    

    Now you can loop over the Items to get the value like this –

    foreach(Person p in grdData.ItemsSource)
    {
       bool isChecked = p.IsManager; // Tells whether checkBox is checked or not
    }
    

    EDIT

    In case you can’t create a property, i would suggest to use the VisualTreeHelper methods to find the control. Use this method to find the child (Maybe you can place this in some utility class and use it, since its generic) –

    public static T FindChild<T>(DependencyObject parent, string childName)
               where T : DependencyObject
    {
       // Confirm parent is valid.  
       if (parent == null) return null;
    
       T foundChild = null;
    
       int childrenCount = VisualTreeHelper.GetChildrenCount(parent);
       for (int i = 0; i < childrenCount; i++)
       {
          var child = VisualTreeHelper.GetChild(parent, i);
          // If the child is not of the request child type child 
          T childType = child as T;
          if (childType == null)
          {
              // recursively drill down the tree 
              foundChild = FindChild<T>(child, childName);
    
              // If the child is found, break so we do not overwrite the found child.  
              if (foundChild != null) break;
          }
          else if (!string.IsNullOrEmpty(childName))
          {
              var frameworkElement = child as FrameworkElement;
              // If the child's name is set for search 
              if (frameworkElement != null && frameworkElement.Name == childName)
              {
                 // if the child's name is of the request name 
                 foundChild = (T)child;
                 break;
              }
          }
          else
          {
              // child element found. 
              foundChild = (T)child;
              break;
           }
       }
       return foundChild;
    }
    

    Now use the above method to get the state of your checkbox –

    for (int i = 0; i < grd.Items.Count; i++)
    {
       DataGridRow row = (DataGridRow)grd.ItemContainerGenerator.ContainerFromIndex(i);
       CheckBox checkBox = FindChild<CheckBox>(row, "chb");
       if( checkBox != null && checkBox.IsChecked == true )
       {
           //some code
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have datagrid with a delete button XAML looks like: <sdk:DataGridTemplateColumn Header=Del/Tgl > <sdk:DataGridTemplateColumn.CellTemplate>
I have this columns in datagrid wpf <DataGrid.Columns> <DataGridComboBoxColumn SelectedItemBinding={Binding Path=ProductId} DisplayMemberPath=Name SelectedValuePath=Id />
So I have this Xaml inside a ListBox Item Template: <ListBox.ItemTemplate> <DataTemplate> <Grid Height=22
I have this code in XAML <Grid x:Name=LayoutRoot Background=Transparent> <Grid.RowDefinitions> <RowDefinition Height=Auto/> <RowDefinition Height=*/>
currently I have this in my XAML: <phone:PhoneApplicationPage.Resources> <toolkit:RelativeTimeConverter x:Key=RelativeTimeConverter/> </phone:PhoneApplicationPage.Resources> .... <TextBlock x:Name=txtTimeAdded
this is my xaml code. <sdk:DataGrid x:Name=dgMarks CanUserResizeColumns=False SelectionMode=Single AutoGenerateColumns=False VerticalAlignment=Top IsReadOnly=True Margin=13,44,0,0 RowDetailsVisibilityChanged=dgMarks_RowDetailsVisibilityChanged
i have a datagrid declared in the xaml as follows: <sdk:DataGrid x:Name=ProductsForProjectDataGrid AutoGenerateColumns=True ItemsSource={Binding
I have a following XAML: <DataGrid Name=nodeDataGrid ItemsSource={Binding NodeList} AutoGenerateColumns=False RowBackground=White AlternatingRowBackground=AliceBlue Grid.Column=1 HorizontalAlignment=Stretch
I have this DataGrid I want to change the Disabled behaviour (xaml); I want
I have this Xaml Code and I want to get the DataGrid dgRemplacement, I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.