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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:02:50+00:00 2026-06-02T02:02:50+00:00

I have a ListBox (WPF) and I am adding to it strings at runtime….

  • 0

I have a ListBox (WPF) and I am adding to it strings at runtime….
If I try to add string that is already exists in the ListBox it throws me an exception….. telling that this item is already in the ListBox….
How can I add the same strings to ListBox ?
Because I have situations in my application when I do have to add 2 identical strings….
thanks….

The ListBox –

<ListBox x:Name="listBox_MyListBox" Height="Auto" Width="Auto" Background="Transparent" MaxHeight="170" BorderThickness="0" Margin="3">
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <TextBlock Margin="3" Padding="2" Text="{Binding}" TextAlignment="Center" FontSize="13"/>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>

in the code behind I add the string like that –

 this.listBox_MyListBox.Items.Add(text.ToString());
  • 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-06-02T02:02:52+00:00Added an answer on June 2, 2026 at 2:02 am

    Yes, you can add duplicate items to listbox, it allows without any issue
    Example:

    private void Window_Loaded ( object sender, RoutedEventArgs e )
    {
       listBox_MyListBox.Items.Add ( "demo" );
       listBox_MyListBox.Items.Add ( "demo" );            
    }
    

    Note:
    It would not let you add duplicate if you are using any of data sources which dont allow duplicate:
    Dictionary or Hashtable may not allow duplicate entries, if that is the case with you then choose List or datatable as datasource

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

Sidebar

Related Questions

I have defined style for my WPF listbox but am adding a rectangle manually
I have a WPF ListBox that I would like to Enable multiple selection in
I have created styled a ListBox in WPF so that it is rendered as
I am new to WPF. I have a ListBox that has its ItemSource set
I have a WPF Listbox filled with children that fire events. Now, I am
I have a WPF Listbox defined in a DataTemplate that has its ItemsSource bound
I have a WPF listbox control that is declaratively bound to a textbox. The
I have a WPF ListBox with a defined DataTemplate. In that template, I have
I have a listbox in WPF that's bound to a ObservableCollection using the ItemSource
I have a WPF ListBox that typically shows 4 or 5 items. For my

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.