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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:39:24+00:00 2026-06-06T01:39:24+00:00

I am new in Binding and WPF recently I’ve learned how to create a

  • 0

I am new in Binding and WPF recently I’ve learned how to create a listBox with multiple columns using Binding tech

 <ListView ItemsSource="{Binding Items}" Margin="306,70,22,17" MouseDoubleClick="listBoxSS_MouseDoubleClick" Name="listBoxSS" >           
    <ListView.View>
            <GridView>
                <GridView.Columns>
                    <GridViewColumn Header="first_name " Width="100" DisplayMemberBinding="{Binding Path=First_name}" />
                    <GridViewColumn Header="last_name" Width="100" DisplayMemberBinding="{Binding Path=Last_name}" />
                    <GridViewColumn Header="phone_number" Width="100" DisplayMemberBinding="{Binding Path=Phones[0]}" />
                    <GridViewColumn Header="notes" Width="100" DisplayMemberBinding="{Binding Path=Notes}" />
                </GridView.Columns>
            </GridView>
        </ListView.View>
    </ListView>

and this is the code:

List<Student> arr = search.students();
        listBoxSS.ItemsSource = arr;

but the problem was when I tried to use add or remove item or clear

 listBoxSS.Items.Clear();

Please I need an example for using the items source or the way that I can ADD or Remove Item or Clear the list.

EDIT:

<ListView ItemsSource="{Binding Items}" Margin="306,70,22,17" MouseDoubleClick="listBoxSS_MouseDoubleClick" Name="listBoxSS" >
    <ListView.View>
        <GridView>
            <GridView.Columns>
                <GridViewColumn Header="first_name " Width="100" DisplayMemberBinding="{Binding Path=First_name}" />
                <GridViewColumn Header="last_name" Width="100" DisplayMemberBinding="{Binding Path=Last_name}" />
                <GridViewColumn Header="phone_number" Width="100" DisplayMemberBinding="{Binding Path=Phones[0]}" />
                <GridViewColumn Header="notes" Width="100" DisplayMemberBinding="{Binding Path=Notes}" />
            </GridView.Columns>
        </GridView>
    </ListView.View>
</ListView>

and here is the code:

 ObservableCollection<Employee> Gemployees;
var employees = new ObservableCollection<Employee>(search.employees());

search.employees() get the list of all employees in my DB

 listBoxPE.ItemsSource = employees;
        Gemployees = employees;

now I can perform all the methods on Gemployees

 Gemployees.Remove((Student)listBoxSS.SelectedItem);
 Gemployees.Add((Student)listBoxSS.SelectedItem);

The ListView perform a refresh whenever I add or remove an Item from Gemployees!! Cool but still a little hard work on binding. Now I am doing an interface class to every ListView so I can put my stuff into it. It wont perform any flexibility in Adding Items.

  • 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-06T01:39:26+00:00Added an answer on June 6, 2026 at 1:39 am

    You’re binding the ItemsSource to a property in the DataContext called Items, so to update the collection, you need to go to the Items property in the DataContext and clear it.

    In addition, the Items property needs to be of type ObservableCollection, not List if you want it to update the UI whenever the underlying collection changes.

    Your bit of code that sets the ItemsSource in the code behind is not needed and should be removed. You only need to set the ItemsSource in one place, not both.

    Here’s a simple example of how it can work:

    // Using Students instead of Items for the PropertyName to clarify
    public ObservableCollection<Student> Students { get; set; }
    
    public MyConstructor()
    {
        ...
    
        Students = search.students();
        listBoxSS.DataContext = this;
    }
    

    Now when you have:

    <ListView ItemsSource="{Binding Students}" ... />
    

    you’re binding the ItemsSource to the ObservableCollection<Student>, and when you want to clear the list you can call:

    Students.Clear()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I create DataGrid Columns with Binding (where i is a Int value): dataGrid.Columns.Add(new DataGridTextColumn
I'm new to WPF data binding. I have a ListBox on a form that
I am new to WPF data binding / style / templates... I am trying
I have a WPF sorting/binding issue. (Disclaimer: I am very new to WPF and
I have recently stumbled across an issue where the WPF ListView control seems to
I am new to WPF and am trying to create a WPF control that
I'm new to WPF and I'm trying to figure out how data binding works,
I have DataGrid with explicitly created columns in code. I am binding WPF element
I am pretty new to binding, and WPF in general. Now I have created
I have trouble getting a binding done using the WPF. I have a model

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.