Cannot Edit Cell on Databound Grid

2 posts, 1 answers
  1. Jassfer
    Jassfer avatar
    1 posts
    Member since:
    Mar 2016

    Posted 24 Mar Link to this post

    Hi,

    I'm still new to Telerik and i'm having a hard time editing specific cell in the grid when user selected the row. 

    below is my Linq datasource.

    var voters = (
                   from voter in db.VotersLists
                         .OrderBy(c => c.Barangay)
                   from data in db.VotersDatas
                       .Where(b => b.RecId == voter.ID)
                       .DefaultIfEmpty()
                   from leader in db.VotersLists
                       .Where(d => d.ID == data.LeaderID)
                       .DefaultIfEmpty()
                   select new
                   {
                       ID = voter.ID,
                       VotersID = voter.VotersID,
                       Precinct = voter.Precinct,
                       Name = voter.Name,
                       Birthday = voter.Birthday.GetValueOrDefault().ToShortDateString(),
                       Sex = voter.Sex,
                       Barangay = voter.Barangay,
                       Address = voter.Address,
                       PoliticalParty = data.PoliticalParty,
                       IsRD = data.IsRD,
                       LeaderName = leader.Name,
                       LeaderPosition = data.LeaderPosition
                       ,DataID = data.ID.ToString() == null ? "" : data.ID.ToString()
                   });
                  dg2.DataSource = voters;

    I tried using the code below and it won't work.

         dg2.Rows[dg2.CurrentRow.Index].Cells[10].Value = "Test";
         
    or
           
         if (this.dg2.CurrentRow is GridViewRowInfo)
         {
             GridViewRowInfo editRow = dg2.CurrentRow;
             editRow.Cells["LeaderName"].Value = "TEST";
          }

     

     

  2. Answer
    Dess
    Admin
    Dess avatar
    1609 posts

    Posted 25 Mar Link to this post

    Hello Jassfer,

    Thank you for writing.

    Such a query will return a list of anonymous objects. The objects in that list are read-only and that is why you cannot edit them in the grid. In this case, you have two options:
    1. Change the value in the data source manually when it is changed in the grid, execute the query again and rebind the grid. 
    2. Use RadVirtualGrid, this can save you the rebinding operation, but you will have to add some code to populate the grid. Detailed information about this is available here: Populating with Data.

    I hope this information is useful.
     
    Regards,
    Dess
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top