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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:32:13+00:00 2026-05-23T00:32:13+00:00

Goal: Need to make selection of a single row included button in the listview.

  • 0

Goal:
Need to make selection of a single row included button in the listview.

Problem:
Don’t know how to make a single selection in the listview when you are clicking on the button that is located inside of listview. In a simple explanation, when clicking on the button, no selection will be applied in the listview’s row

It would be great if selection is applied before entering button’s method cuz i need to grab information from the single selection of the listview that should be sent to business logic.


private void btnBuy_Click(object sender, RoutedEventArgs e)
{

}
<ListView Height="242.47" Canvas.Left="8" Canvas.Top="49.53" Width="435.22" Name="lstOrder" ItemsSource="{Binding}"
        PreviewMouseLeftButtonUp="lstOrder_PreviewMouseLeftButtonUp" SelectionChanged="lstOrder_SelectionChanged"
        SelectionMode="Single">
    <ListView.View>
        <GridView>
            <GridViewColumn Header="Article Number" Width="auto" DisplayMemberBinding="{Binding Path=_articleNumber}"
                    TextBlock.TextAlignment="Left"
                    HeaderContainerStyle="{StaticResource ListViewHeaderRightAlignedStyle}" />
            <GridViewColumn Header="Name" Width="auto" DisplayMemberBinding="{Binding Path=_name}"
                    TextBlock.TextAlignment="Left"
                    HeaderContainerStyle="{StaticResource ListViewHeaderRightAlignedStyle}" />
            <GridViewColumn Header="Sale Price" Width="auto" DisplayMemberBinding="{Binding Path=_salePrice}"
                    TextBlock.TextAlignment="Left"
                    HeaderContainerStyle="{StaticResource ListViewHeaderRightAlignedStyle}" />
            <GridViewColumn Header="Product Category" Width="auto"
                    DisplayMemberBinding="{Binding Path=_productCategory}" TextBlock.TextAlignment="Left"
                    HeaderContainerStyle="{StaticResource ListViewHeaderRightAlignedStyle}" />
            <GridViewColumn Header="Quantity" Width="auto" DisplayMemberBinding="{Binding Path=_quantity}"
                    TextBlock.TextAlignment="Left"
                    HeaderContainerStyle="{StaticResource ListViewHeaderRightAlignedStyle}" />
            <GridViewColumn>
                <GridViewColumn.CellTemplate>
                    <DataTemplate>
                        <Button Name="btnBuy" MinHeight="20" MinWidth="50" Content="Buy" Click="btnBuy_Click" />
                    </DataTemplate>
                </GridViewColumn.CellTemplate>
            </GridViewColumn>
        </GridView>
    </ListView.View>
</ListView>

namespace MediaStore
{
    /// <summary>
    /// Interaction logic for Counter.xaml
    /// </summary>
    public partial class Counter : Window
    {
        private ManagerProduct _myManagerProduct;
        private ManagerCart _myManagerCart;

    public Counter(ManagerProduct pManagerProduct, ManagerCart pMyManagerCart)
    {
        this.InitializeComponent();

        _myManagerProduct = pManagerProduct;
        _myManagerCart = pMyManagerCart;


        lstOrder.AddHandler(ListViewItem.UnselectedEvent, new RoutedEventHandler(ItemSelected), true);


        UpDateGUI();
    }


    public void UpDateGUI()
    {
        FillDataInListView();
    }

    private void FillDataInListView()
    {
        lstOrder.DataContext = _myManagerProduct.GetAllProductList();
    }

    #region Tab Order - 1. Order

    private void btnBuy_Click(object sender, RoutedEventArgs e)
    {

    }

    private void btnDisplayCart_Click(object sender, RoutedEventArgs e)
    {

    }

    private void btnCheckout_Click(object sender, RoutedEventArgs e)
    {
        cvsOrder.Visibility = Visibility.Hidden;

        cvsConfirmation.Margin = new Thickness(8, 8, 8, 17);
    }

    private void lstOrder_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
    {


    }


    private void ItemSelected(object sender, RoutedEventArgs e)
    {

    }


    private void lstOrder_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {

    }
    #endregion

    }

}
  • 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-23T00:32:14+00:00Added an answer on May 23, 2026 at 12:32 am

    You should not need to select the ListViewItem, you can get your dataobject from the DataContext of the Button and you don’t need the data from other rows since you wanted a single selection anyway.

    In the event-handler:

    var data = (sender as FrameworkElement).DataContext as MyData;
    

    (On a side note, that being said, do you need selection at all? If not use an ItemsControl)

    To make the ListViewItem select itself if the button is clicked you can use a ItemContainerStyle like this:

    <ListView.ItemContainerStyle>
        <Style TargetType="{x:Type ListViewItem}">
            <Setter Property="IsSelected"
                    Value="{Binding RelativeSource={RelativeSource Self}, Path=IsKeyboardFocusWithin, Mode=OneWay}" />
        </Style>
    </ListView.ItemContainerStyle>
    

    Here is an alternative using an animation which preserves the selected item after the ListView looses focus (only works with ListView.SelectionMode being Single as it does not seem to be possible to clear the previous selection using an animation):

    <Style TargetType="{x:Type ListViewItem}">
        <Style.Triggers>
            <DataTrigger
                    Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsKeyboardFocusWithin, Mode=OneWay}"
                    Value="True">
                <DataTrigger.EnterActions>
                    <BeginStoryboard>
                        <Storyboard>
                            <BooleanAnimationUsingKeyFrames Storyboard.TargetProperty="IsSelected">
                                <DiscreteBooleanKeyFrame KeyTime="0" Value="True" />
                            </BooleanAnimationUsingKeyFrames>
                        </Storyboard>
                    </BeginStoryboard>
                </DataTrigger.EnterActions>
            </DataTrigger>
        </Style.Triggers>
    </Style>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Goal: Gain datatype date with year and month Problem: Need to help to convert
I have maven-plagin and need to run goal, that should automatically run before plugin.
Goal is to make a dialog that appears on menu_key pressed, but it keeps
I know a little python and thats about it. My goal is to make
The desired goal: I am trying to make an email current page button to
Like the title says, I need to make a very customized view that behaves
I need a solution to hide/show a checkbox depending a radio button selection. I
I'd like to make a record as an object's property. The problem is that
My goal is to make a modern webapp that uses location hash for navigation
Goal I need to alter a number of almost identical triggers on a number

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.