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 826071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:21:21+00:00 2026-05-15T03:21:21+00:00

Been trying to figure out, how do I capture the events from a listbox.

  • 0

Been trying to figure out, how do I capture the events from a listbox. In the template, I’ve added the parameter IsChecked=”” which starts my method. However, the problem is trying to capture what has been checked in the method. SelectedItem only returns what is currently selected, not the checkbox.

object selected = thelistbox.SelectedItem;
DataRow row = ((DataRowView)selected).Row;
string teststring = row.ItemArray[0].ToString();    // Doesn't return the checkbox!

<ListBox IsSynchronizedWithCurrentItem="True" Name="thelistbox" ItemsSource="{Binding mybinding}">
    <ListBox.ItemTemplate>
            <DataTemplate>
                    <StackPanel>
                            <CheckBox Content="{Binding personname}" Checked="CheckBox_Checked" Name="thecheckbox"/>
                        </StackPanel>
                </DataTemplate>
        </ListBox.ItemTemplate>
</ListBox>
  • 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-05-15T03:21:22+00:00Added an answer on May 15, 2026 at 3:21 am

    Ideally you should bind IsChecked to a property on your row i.e.

    <CheckBox Content="{Binding personname}" IsChecked="{Binding IsPersonChecked}" Name="thecheckbox"/>
    

    where “IsPersonChecked” is column in your DataTable (or whatever you bind to), just like “personname”. Then you can read whether it is checked directly from your DataRow variable:

    DataRow row = ((DataRowView)thelistbox.SelectedValue).Row;
    bool isPersonChecked = (bool) row["IsPersonChecked"];
    

    If DataSet is typed, you want to use typed DataRow properties, obviously.

    Note that I used SelectedValue, not SelectedItem property. I believe SelectedItem is actually an instance of ListBoxItem. Which you can use if you want to leave your IsChecked unbound. Then you’d have to retrieve CheckBox considering full template hierarchy. Something like:

    bool isChecked = ((CheckBox)((StackPanel) ((ListBoxItem) thelistbox.SelectedItem).Content).Children[0]).IsChecked ?? false;
    

    Messy. (Debug and adjust the hierarchy to what you’ll actually get. My code wont probably work as is.)

    Better approach is to use RoutedEventArgs of your CheckBox_Checked handler:

    private void CheckBox_Checked(object sender, RoutedEventArgs e)
    {
        CheckBox checkBox = (CheckBox) e.Source;
        DataRow row = ((DataRowView) checkBox.DataContext).Row;
        bool isChecked = checkBox.IsChecked ?? false;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to figure out a way to tag several methods from
I've been trying figure out how to add a handler to a method using
I've been trying to figure out how BrowserStack has added Firebug Lite as an
So I've been trying to figure out how to use template specialization but ran
I have been trying to figure out the following excerpt from Ruby on Rails
I have been trying to figure out a solution but nothing has really presented
I've been trying to figure out how to write this regular expression. It is
I've been trying to figure out how to iterate over the list of columns
I've been trying to figure out how I can make a query with MySQL
Hello I been trying to figure out how to set up ASP.Net forms authentication

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.