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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:54:37+00:00 2026-05-17T16:54:37+00:00

I am binding an observable collection to my gridview. public ObservableCollection<LibraryTrack> Biblio { get

  • 0

I am binding an observable collection to my gridview.

    public ObservableCollection<LibraryTrack> Biblio
    { get { return _Biblio; } }

The gridview only contains the necessary values for the user to see. The secondary information like filelocation and file id isn’t bound to the gridview, this info is in this case useless for the user to see.

First some code:

    <GridView x:Key="gridview">
        <GridViewColumn Width="200" 
                                        HeaderContainerStyle="{StaticResource hcs}"
                                        DisplayMemberBinding="{Binding Title}">
            <GridViewColumnHeader Content="Titel" Tag="Title" Click="SortClick"/>
        </GridViewColumn>
        <GridViewColumn Width="200" 
                                        HeaderContainerStyle="{StaticResource hcs}"
                                        DisplayMemberBinding="{Binding Artist}">
            <GridViewColumnHeader Content="Artiest" Tag="Artist" Click="SortClick"/>
        </GridViewColumn>
        <GridViewColumn Width="200" 
                                        HeaderContainerStyle="{StaticResource hcs}"
                                        DisplayMemberBinding="{Binding Album}">
            <GridViewColumnHeader Content="Album" Tag="Album" Click="SortClick"/>
        </GridViewColumn>
        <GridViewColumn Width="50" 
                                        HeaderContainerStyle="{StaticResource hcs}"
                                        DisplayMemberBinding="{Binding Genre}">
            <GridViewColumnHeader Content="Genre" Tag="Genre" Click="SortClick"/>
        </GridViewColumn>
        <GridViewColumn Width="50" 
                                        HeaderContainerStyle="{StaticResource hcs}"
                                        DisplayMemberBinding="{Binding Jaar}">
            <GridViewColumnHeader Content="Jaar" Tag="Jaar" Click="SortClick"/>
        </GridViewColumn>
    </GridView>

Sorting is enabled via code and works perfectly. In the code behind, I have the following event handler:

    private void SortClick(object sender, RoutedEventArgs e)
    {
        GridViewColumnHeader column = sender as GridViewColumnHeader;
        String field = column.Tag as String;

        if (_CurSortCol != null)
        {
            AdornerLayer.GetAdornerLayer(_CurSortCol).Remove(_CurAdorner);
            LibView.Items.SortDescriptions.Clear();
        }
        ListSortDirection newDir = ListSortDirection.Ascending;
        if (_CurSortCol == column && _CurAdorner.Direction == newDir)
            newDir = ListSortDirection.Descending;

        _CurSortCol = column;
        _CurAdorner = new SortAdorner(_CurSortCol, newDir);
        AdornerLayer.GetAdornerLayer(_CurSortCol).Add(_CurAdorner);
        LibView.Items.SortDescriptions.Add(new SortDescription(field, newDir));   
    }

Libview is the ListView containing the gridview. to start playing the selected song I use next code:

    private void BtnPlay_Click(object sender, RoutedEventArgs e)
    {
        if (LibView.SelectedIndex == -1)
        {
            LibView.SelectedIndex = 0;
        }
            LibraryTrack curtrack = Biblio[LibView.SelectedIndex];
            songInfoLabel1.Text = curtrack.Title + "\n" +
                                  curtrack.Artist + "\n" +
                                  curtrack.Album + "\n" +
                                  curtrack.Jaar;
            MediaEl.Source = new Uri(curtrack.Location);
            MediaEl.Play();    
    }

Here comes my problem. As long as the gridview isn’t sorted Btn_Play_Click handles everything just fine.

But when I sort the rows the Btn_Play_Click starts the wrong song.
How can I fix this?

  • 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-17T16:54:37+00:00Added an answer on May 17, 2026 at 4:54 pm

    Instead of using Biblio[LibView.SelectedIndex] to get the selected LibraryTrack, just use LibView.SelectedItem instead.

    LibraryTrack curtrack = LibView.SelectedItem as LibraryTrack;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm binding a GridView to a collection of objects that look like this: public
Here's my binding source object: Public Class MyListObject Private _mylist As New ObservableCollection(Of String)
I am working with MVVM and WPF. VM contains - an Observable collection of
I have an ObservableCollection of addresses that I am binding to a ListBox. Then
Binding a List collection to a datagrid. How can you limit what properties will
1) Binding to The following populates a READ ONLY WinFrms grid: Dim query =
When Binding a GridView to a DataTable, How can we Change the value displayed
I'm binding a datatable to a gridview control, and when I format each column
I have an observable collection bound to a listbox in WPF. One of the
I have an observable collection of Song objects. These song objects have a property

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.