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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T14:56:23+00:00 2026-05-11T14:56:23+00:00

I have a sorted listbox and need to display each item’s row number. In

  • 0

I have a sorted listbox and need to display each item’s row number. In this demo I have a Person class with a Name string property. The listbox displays a a list of Persons sorted by Name. How can I add to the datatemplate of the listbox the row number???

XAML:

<Window x:Class='NumberedListBox.Window1'     xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'     xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'     Height='300' Width='300'>     <ListBox          ItemsSource='{Binding Path=PersonsListCollectionView}'          HorizontalContentAlignment='Stretch'>         <ListBox.ItemTemplate>             <DataTemplate>                 <TextBlock Text='{Binding Path=Name}' />             </DataTemplate>         </ListBox.ItemTemplate>     </ListBox> </Window> 

Code behind:

using System; using System.Collections.ObjectModel; using System.Windows.Data; using System.Windows; using System.ComponentModel;  namespace NumberedListBox {     public partial class Window1 : Window     {         public Window1()         {             InitializeComponent();              Persons = new ObservableCollection<Person>();             Persons.Add(new Person() { Name = 'Sally'});             Persons.Add(new Person() { Name = 'Bob' });             Persons.Add(new Person() { Name = 'Joe' });             Persons.Add(new Person() { Name = 'Mary' });              PersonsListCollectionView = new ListCollectionView(Persons);             PersonsListCollectionView.SortDescriptions.Add(new SortDescription('Name', ListSortDirection.Ascending));              DataContext = this;         }          public ObservableCollection<Person> Persons { get; private set; }         public ListCollectionView PersonsListCollectionView { get; private set; }     }      public class Person     {         public string Name { get; set; }     } } 
  • 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. 2026-05-11T14:56:24+00:00Added an answer on May 11, 2026 at 2:56 pm

    This should get you started:

    http://weblogs.asp.net/hpreishuber/archive/2008/11/18/rownumber-in-silverlight-datagrid-or-listbox.aspx

    It says it’s for Silverlight, but I don’t see why it wouldn’t work for WPF. Basically, you bind a TextBlock to your data and use a custom value converter to output the current item’s number.

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

Sidebar

Ask A Question

Stats

  • Questions 134k
  • Answers 135k
  • 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 For full information associated with that tag, use command git… May 12, 2026 at 6:54 am
  • Editorial Team
    Editorial Team added an answer You should try using the hoverIntent plugin. This is what… May 12, 2026 at 6:54 am
  • Editorial Team
    Editorial Team added an answer "hello _there_".replace(/_(.*?)_/, function(a, b){ return '<div>' + b + '</div>';… May 12, 2026 at 6:54 am

Related Questions

I have a sorted listbox and need to display each item's row number. In
I've got an ObservableCollection assigned to ItemsSource of a listbox. Listbox is using a
Consider this code (type names genericised for the purposes of example): // Bound to
I have a sorted collection of objects (it can be either SortedList or SortedDictionary,
I have a sorted array of 5000 integers. How fast can I tell if

Trending Tags

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

Top Members

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.