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

  • Home
  • SEARCH
  • 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 1033005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:10:06+00:00 2026-05-16T14:10:06+00:00

I have a WPF ListView control for which I am dynamically creating columns. One

  • 0

I have a WPF ListView control for which I am dynamically creating columns. One of the columns happens to be a CheckBox column. When the user directly clicks on the CheckBox the ListView’s SelectedItem is not changed. Had the checkbox been declared in XAML I would have added handling for the Click event to manually set the selection. However, I’m stumped since it’s a dynamic column.

<ListView
    SelectionMode="Single"
    ItemsSource="{Binding Documents}"                    
    View="{Binding Converter={local:DocumentToGridViewConverter}}" />

The converter takes in an object that has Properties associated with it, there is a name/value pair that can be referenced through indexers.

public class DocumentToGridViewConverter : MarkupExtension, IValueConverter
{
    private static DocumentToGridViewConverter mConverter;

    public object Convert( object value, Type targetType, object parameter, CultureInfo culture )
    {
        GridView gridView = null;

        Document document = value as Document;
        if( document != null )
        {
            // Create a new grid view.
            gridView = new GridView();

            // Add an isSelected checkbox complete with binding.
            var checkBox = new FrameworkElementFactory( typeof( CheckBox ) );
            gridView.Columns.Add( new GridViewColumn
            {
                Header = string.Empty, // Blank header
                CellTemplate = new DataTemplate { VisualTree = checkBox  },
            } );

            // Add the rest of the columns from the document properties.
            for( int index = 0; index < document.PropertyNames.Length; index++ )
            {
                gridView.Columns.Add( new GridViewColumn
                {
                    Header = document.PropertyNames[index];
                    DisplayMemberBinding = new Binding(
                        string.Format( "PropertyValues[{0}]", index ) )
                } );
            }
        }

        return gridView;
    }

    public object ConvertBack( object value, Type targetType, object parameter, CultureInfo culture )
    {
        throw new NotImplementedException();
    }

    public override object ProvideValue( IServiceProvider serviceProvider )
    {
        if( mConverter == null )
        {
            mConverter = new DocumentToGridViewConverter();
        }
        return mConverter;
    }
}

So, my question is how do I dymaically create a CheckBox that will cause the ListView row to be select when the user clicks on the CheckBox.

Thanks!

EDIT:

This question are similar, but doesn’t have the dynamic piece: WPF ListView SelectedItem is null

  • 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-16T14:10:06+00:00Added an answer on May 16, 2026 at 2:10 pm

    One way of solving this is to create a ‘ChildSelectionCompatibleListBoxItem’ which derives from ‘ListBoxItem’ and manually handle selection in the PreviewMouseDown/Up events. Note that its get trickier when you are using SelectionMode.Extended

    Another way is to create a derived ListBoxSelectionCompatibleCheckBox which ‘escapes’ mouse events when the parent ListBoxItem is not yet selected.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 522k
  • Answers 522k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You could use a derived table to simulate a first… May 16, 2026 at 9:23 pm
  • Editorial Team
    Editorial Team added an answer Taking advantage of str.split's behavior with no sep parameter: >>>… May 16, 2026 at 9:23 pm
  • Editorial Team
    Editorial Team added an answer No. JavaScript in web browsers is not only single threaded,… May 16, 2026 at 9:23 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Couldn't find an answer to this one. I have a WPF ListView control that
I have a ListView with a CheckBox as one of the columns, bound to
I have a wpf control named DataPicker which has a dependency property named SelectedDate.
I am designing a WPF user control which contains other user controls (imagine a
I have a list of objects which i want to bind to a ListView
I have a listview control that is bound to an observable collection that I
I have an action Edit in my WPF application, which is bound to items
I am trying to bind a data class to a ListView control in WPF,
Greetings, In an WPF DataGridTemplateColumn I have a CellTemplate using a ListView and a
I'm just getting started with Linq-to-SQL and data binding in WPF, most of which

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.