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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:26:16+00:00 2026-06-14T02:26:16+00:00

My problem is operating with a list and a listview. The Listview’s itemsSource property

  • 0

My problem is operating with a list and a listview. The Listview’s itemsSource property is bound to a list in my class(say List).

I want to both modify existing items and add new items to the list. For this reason, I’ve made text boxes for each element in the class Contact(name, surname, …)

Now If I want to modify the selected item, I set the Text property of each textbox to this:

<TextBox Text="{Binding ElementName=listView1, Path=SelectedItem.Name}"/>

If I want to create new element. I’ve got to do this:

<TextBox Text="{Binding ElementName=tempContact, Path=Name}"/>

where tempContact is an instance of the Contact class that is lately added to the list via a button.

Problem is I want to do both adding and modifying the elements of this list and I need an idea. Could anyone give me a hand?

  • 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-14T02:26:17+00:00Added an answer on June 14, 2026 at 2:26 am

    To add an item to list from TextBox, create a property of string type in your ViewModel and notify when the property changes. You have to create a similar property for edit too and also to store current index of selected item from the ListView

    string contactName;
    public string ContactName
    {
        get 
        {
           return contactName; 
        }
        set 
        {
           contactName = value; 
           OnPropertyChanged("ContactName");
        }
    }
    
    private string editedName;
    public string EditedName
    {
        get { return editedName; }
        set
        {
            editedName = value;
            OnPropertyChanged("EditedName");
        }
    }
    
    private int selectedIndex;
    public int SelectedIndex
    {
        get { return selectedIndex; }
        set
        {
            selectedIndex = value;
            OnPropertyChanged("SelectedIndex");
        }
    }
    

    Add TextBoxes and ListBox to your view and apply bindings. This is the tricky part. Because, when you choose an item from the ListView, index of the selected item has to be stored in the SelectedIndex property, selected contact name should be bound to the TextBox used to edit the value.

    <ListBox  Name="contactNames" SelectedIndex="{Binding SelectedIndex}" ItemsSource="{Binding ContactNames}" SelectedItem="{Binding EditedName}" />
    <TextBox Name="addNameTextBox" Text="{Binding ContactName}" />
    <TextBox Name="editNameTextBox" Text="{Binding EditedName}" />
    

    In the Command method that handles the button click, add logic to add or edit an item based on the properties set.

    if (EditedName != null && EditedName != string.Empty)
    {                
        ContactNames[SelectedIndex] = EditedName;
        EditedName = string.Empty;
    }
    else if (ContactName!=null && ContactName != string.Empty)
    {
        ContactNames.Add(ContactName);
        ContactName = string.Empty;
    }
    

    Don’t forget to create your list as an ObservableCollection. Otherwise, the LisView will not be notified about the changes made to list.

    Hope this helps.

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

Sidebar

Related Questions

Say I have a list and I want it arranged so that the sum
Problem: I am using Windows as a guest operating system in a Virtual Machine
Problem: I've written State Machine for my android application. It is separate class, extension
Problem: Activity A is a ListView that contains a ListAdapter , and clicking in
Hi I'm having problem refreshing my listview after Async operation. I have a simplecursoradapter,
Problem Step 1 : Given a list of numbers, generate all possible groupings (in
I have a ListView with a customized filter and a customized sort Comparator. Both
I have a problem with list operations in Scala. I'm trying to implement the
This is NOT the problem about detecting cycle in a linked list using the
I have a listview which I populate from a webservice query. Problem is that

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.