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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:29:30+00:00 2026-06-08T12:29:30+00:00

A little back story here. I’ve got a public property (typeof(ObservableCollection<Area>)) that I bind

  • 0

A little back story here. I’ve got a public property (typeof(ObservableCollection<Area>)) that I bind a treeview to. I’d like to update the tree, but I don’t want to redraw the whole thing and lose the selected item, collapsed/expanded states of nodes and anything else I forget to implement. So I think I need to update the Area within the collection. I notice that using a FirstOrDefault statement and setting it equal to something does not actually change the Area in the observable collection:

var areas = GetAreaInfo(); //Entity Framework query returns ObservableCollection<Area>
foreach (Area a in areas)
{
    var αrea = Areas.FirstOrDefault(α => α.Id == a.Id);
    if (αrea != null)
        αrea = a;  //αrea changes, but Area[0] which is supposed to be αrea doesn't
}

Can I get a reference or pointer to the object so I don’t have to iterate through the observable collection and use indexes?

  • 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-08T12:29:31+00:00Added an answer on June 8, 2026 at 12:29 pm

    You’re not actually doing what you think you’re doing. In your case, area is just a variable. When you set area = a, you’re resetting the location that the ‘area’ variable is pointing to, not changing the observable collection at all.

    Your best bet is to update all of the properties of area to match the properties of a. It’s usually easy enough to write a Clone or Copy method to copy the properties from one instance of the object onto another instance. Your other option is to remove area from the collection and add a instead, but that is likely to cause some problems with ordering.

    EDIT: And on your actual question, yes, it’s possible to get pointers in C#, but it’s a bad idea. It will take a lot more work to write, requires you to mark you code as unsafe, and will be more difficult to maintain going forward.

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

Sidebar

Related Questions

a little back story: I am working on a file that got to be
A little back story : I have small application that will use Word to
I little while back I posted this question . I have updated that question
Just need a little bit of Javascript to warn people that press the back
The story behind... I really like TV shows but I go back home only
Back story i have a table that stores cached times, and currently has about
Background Story A little back story before i get to the question. I'm working
The Back Story A little while back, I was asked if we could implement
I'm currently writing myself a little C# back up program. I'm using a standard
a few years back in college I wrote TONS of simple little java programs...

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.