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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:24:48+00:00 2026-06-15T09:24:48+00:00

I’m working with a particular table from the backing database which uses a relevant

  • 0

I’m working with a particular table from the backing database which uses a relevant data item as the primary key (in this case, the users’ initials). This is something I can’t change; it’s a legacy design, so I’m stuck with it. But because it’s relevant, it has to be shown in the DataGrid I’m working with (bound to the table in the database through an ObjectContext.)

Unfortunately, this means that when a user tries to edit the initials on an existing record, an exception is thrown, because they’re trying to edit the entity key of the entity corresponding to this table.

Which is all very well, since they don’t need to and indeed shouldn’t be editing that column, and so under ordinary circumstances, I’d just mark the column read-only. Trouble is, I do need them to be able to enter new records in the table, but if I mark the column read-only, they can’t enter the initials in the “new row”. either.

How can I make all the cells in this column read-only except for the one in the “new row”?

(Or is my whole approach here fundamentally misguided – bearing in mind that I can’t change the table, and this field needs to exist and be insertable by users, albeit not updateable?)

  • 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-15T09:24:49+00:00Added an answer on June 15, 2026 at 9:24 am

    The above answer from Ron solved half my problem (thanks muchly!), the other half being detecting which cells were part of the “new row” in the first place. That answer, though, came to me with a little experimentation – checking the EntityState of the entity attached to the row will tell you that, since it is “Detached” when you’re in the “new row”, and changes to “Added” once you’ve left it, but before changes are actually saved on the ObjectContext (at which time the entity key column can still be edited freely without causing the error).

    The code to achieve this, therefore, is as follows:

    private void userDataGrid_BeginningEdit(object sender, DataGridBeginningEditEventArgs e)
    {
        if ((string)e.Column.Header == "Initials")
        {
            // If this is the new row, entity is not yet attached to the context.
            if (
                (((User)e.Row.Item).EntityState != EntityState.Detached) &&
                (((User)e.Row.Item).EntityState != EntityState.Added))
            {
                e.Cancel = true;
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string
I have a view passing on information from a database: def serve_article(request, id): served_article
Let's say I'm outputting a post title and in our database, it's Hello Y’all
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small

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.