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 8086061

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:20:08+00:00 2026-06-05T18:20:08+00:00

I have several listviews with two collumns like. I am building a stats application

  • 0

I have several listviews with two collumns like.
I am building a stats application for another application.
Each row should have two columns.
(Name,Sum) or (Name,Count)
The problem is that the model has three(Name,Sum,Count).And i want to have a general switch to determine which column should be shown at all 6 listviews. Is there any solution for this?

  • 0 0 Answers
  • 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-05T18:20:10+00:00Added an answer on June 5, 2026 at 6:20 pm

    You could use a style for the ListView and only add the columns that you want depending on a property that shows which view you’re after.

    CountSumSwitch is a boolean dependency property that I have in MainWindow, you switch it to true to display the counts in all listviews and false to display the sum in all listviews.

         <Style TargetType="{x:Type ListView}">
            <Style.Triggers>
                <!-- This binding needs to point to some global propery that you'll change to switch views.-->
                <DataTrigger Binding="{Binding CountSumSwitch}" Value="True">
                    <Setter Property="View">
                        <Setter.Value>
                            <GridView>
                                <GridViewColumn Width="140" Header="Name" DisplayMemberBinding="{Binding Name}" />
                                <GridViewColumn Width="140" Header="Count" DisplayMemberBinding="{Binding Count}" />
                            </GridView>
                        </Setter.Value>
                    </Setter>
                </DataTrigger>
                <DataTrigger Binding="{Binding CountSumSwitch}" Value="False">
                    <Setter Property="View">
                        <Setter.Value>
                            <GridView>
                                <GridViewColumn Width="140" Header="Name" DisplayMemberBinding="{Binding Name}" />
                                <GridViewColumn Width="140" Header="Sum" DisplayMemberBinding="{Binding Sum}" />
                            </GridView>
                        </Setter.Value>
                    </Setter>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    

    Edit:

    To show this in action I’ll add an example, it shows a listview bound to a collection with a checkbox to toggle the columns that are used. Create a new WPF application, replace the MainWindow class with this

    public partial class MainWindow : Window
        {
    
            public bool CountSumSwitch
            {
                get { return (bool)GetValue(CountSumSwitchProperty); }
                set { SetValue(CountSumSwitchProperty, value); }
            }
    
            public static readonly DependencyProperty CountSumSwitchProperty = DependencyProperty.Register("CountSumSwitch", typeof(bool), typeof(MainWindow), new UIPropertyMetadata(false));
    
    
            public List<TheItem> ITems
            {
                get { return (List<TheItem>)GetValue(ITemsProperty); }
                set { SetValue(ITemsProperty, value); }
            }
    
            public static readonly DependencyProperty ITemsProperty = DependencyProperty.Register("ITems", typeof(List<TheItem>), typeof(MainWindow), new UIPropertyMetadata(null));
    
    
            public MainWindow()
            {
                InitializeComponent();
    
                Random rnd = new Random();
    
                ITems = new List<TheItem>(new TheItem[]
                {
                    new TheItem () { Name = "Item 1", Count = rnd.Next(100), Sum = rnd.Next (100)}, 
                    new TheItem () { Name = "Item 2", Count = rnd.Next(100), Sum = rnd.Next (100)}, 
                    new TheItem () { Name = "Item 3", Count = rnd.Next(100), Sum = rnd.Next (100)}, 
                    new TheItem () { Name = "Item 4", Count = rnd.Next(100), Sum = rnd.Next (100)}, 
                    new TheItem () { Name = "Item 5", Count = rnd.Next(100), Sum = rnd.Next (100)}, 
                    new TheItem () { Name = "Item 6", Count = rnd.Next(100), Sum = rnd.Next (100)}, 
                    new TheItem () { Name = "Item 7", Count = rnd.Next(100), Sum = rnd.Next (100)}, 
                    new TheItem () { Name = "Item 8", Count = rnd.Next(100), Sum = rnd.Next (100)}, 
                    new TheItem () { Name = "Item 9", Count = rnd.Next(100), Sum = rnd.Next (100)}, 
                });
    
                CountSumSwitch = false;
            }
    
            public class TheItem
            {
                public string Name { get; set; }
                public int Count { get; set; }
                public int Sum { get; set; }
            }
        }
    

    And put this code in the MainWindow.xaml

    <Window x:Class="WpfApplication6.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            DataContext="{Binding RelativeSource={RelativeSource Self}}"
            Title="MainWindow" Height="350" Width="525">
        <Window.Resources>
            <Style TargetType="{x:Type ListView}">
                <Style.Triggers>
                    <!-- This binding needs to point to some global propery that you'll change to switch views.-->
                    <DataTrigger Binding="{Binding CountSumSwitch}" Value="True">
                        <Setter Property="View">
                            <Setter.Value>
                                <GridView>
                                    <GridViewColumn Width="140" Header="Name" DisplayMemberBinding="{Binding Name}" />
                                    <GridViewColumn Width="140" Header="Count" DisplayMemberBinding="{Binding Count}" />
                                </GridView>
                            </Setter.Value>
                        </Setter>
                    </DataTrigger>
                    <DataTrigger Binding="{Binding CountSumSwitch}" Value="False">
                        <Setter Property="View">
                            <Setter.Value>
                                <GridView>
                                    <GridViewColumn Width="140" Header="Name" DisplayMemberBinding="{Binding Name}" />
                                    <GridViewColumn Width="140" Header="Sum" DisplayMemberBinding="{Binding Sum}" />
                                </GridView>
                            </Setter.Value>
                        </Setter>
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </Window.Resources>
        <Grid>
            <CheckBox IsChecked="{Binding CountSumSwitch}"/>
            <ListView ItemsSource="{Binding ITems}" Margin="0,83,0,0"/>
        </Grid>
    </Window>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have ListView that uses a GridView to display several columns of data. Two
I have a listview with several items that are created dynamically, each has two
I have an Arraylist of HashMap . Each HashMap element contains two columns: column
I have a ListView containing several GridViewColumns. Several of the columns are checkboxes. Each
I have a listview and i would like to populate a row with several
I have several similar user controls which display listviews of respectively different data entities.
Background: I have a ListView / GridView with several columns. In some situations, only
I have several buttons. When clicked I would like to remove all classes from
I have several ListActivties set up in my Android Application. What I am trying
I have a ListView with several columns. How can I access the index of

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.