Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. LINQ
  4. Cannot Edit DataGridView when bound to custom LINQ query

Cannot Edit DataGridView when bound to custom LINQ query

Scheduled Pinned Locked Moved LINQ
helpcsharpdatabaselinqquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 1953357
    wrote on last edited by
    #1

    Hello everyone and thank you all in advance for any help. I have the following problem. I bound a DataGridView to a Linq query that goes like this:

    var _query = from p in _cntxt.Product
    select new {p.Name, p.Provider.Name};

    dataGridView1.DataSource = _query;

    The information is shown correctly, but I cannot edit any rows nor columns int he DataGridView I tried to specify each column to be ReadOnly = false; without success. If I change my query's select statement to simply: select p; It works and it allows the rows and columns to be edited. Can anyone help me?:confused: Thnx!

    I 1 Reply Last reply
    0
    • U User 1953357

      Hello everyone and thank you all in advance for any help. I have the following problem. I bound a DataGridView to a Linq query that goes like this:

      var _query = from p in _cntxt.Product
      select new {p.Name, p.Provider.Name};

      dataGridView1.DataSource = _query;

      The information is shown correctly, but I cannot edit any rows nor columns int he DataGridView I tried to specify each column to be ReadOnly = false; without success. If I change my query's select statement to simply: select p; It works and it allows the rows and columns to be edited. Can anyone help me?:confused: Thnx!

      I Offline
      I Offline
      Ian McCaul
      wrote on last edited by
      #2

      The DataGridView will be in ReadOnly mode when you use anonymous types. So what I recommend is defining only those 2 columns in the DataGridView and set AutoGenerateColumns to false and go ahead and use select p;

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups