Update Cell Value

10 posts, 0 answers
  1. Mohsen
    Mohsen avatar
    4 posts
    Member since:
    Aug 2016

    Posted 10 Aug Link to this post

    The following code doesn't work:

    1.string newDate = "...";
    2.grid.CurrentRow.Cells["StartDate"].Value = newDate;

  2. Joe
    Joe avatar
    26 posts
    Member since:
    Feb 2012

    Posted 10 Aug in reply to Mohsen Link to this post

    Mohsen --

     

    What does not work?

    Is grid your grid name?  Try something like the below (adding this. to qualify it)

    What is the error?

    this.report_gridview.CurrentRow.Cells["deliveryID"].Value ="test value"

  3. UI for WinForms is Visual Studio 2017 Ready
  4. Mohsen
    Mohsen avatar
    4 posts
    Member since:
    Aug 2016

    Posted 11 Aug in reply to Joe Link to this post

    I'm going to update a cell value with the following code:

    1.string newDate = "...";
    2.this.radGridView.CurrentRow.Cells["StartDate"].Value = newDate;

    But it doesn't work and no exception occurs. In fact, I think the code works but the grid need to be refreshed. Any idea?

  5. Joe
    Joe avatar
    26 posts
    Member since:
    Feb 2012

    Posted 11 Aug in reply to Mohsen Link to this post

    Is the grid databound?

    If the cell is databound then doing an updated like that won't work, you would have to change the underlying datasource and refresh the grid.

    How are you populating the grid with data?

    Perhaps post the code that is populating the grid.

    There is a Application.DoEvents() but I don't think that is the problem here.

     

  6. Mohsen
    Mohsen avatar
    4 posts
    Member since:
    Aug 2016

    Posted 11 Aug in reply to Joe Link to this post

    Here is the code to fill the gridview:

    01.DateTime today = db.GetServerDate();
    02.            var query = from p in _dbRahat.Projects
    03.            where p.ProjectType_Id == Convert.ToInt32(cmbProjectTypes.SelectedValue)
    04.            orderby p.Code
    05.            select new
    06.            {
    07.               p.Id,
    08.               p.Title,
    09.               p.Code,
    10.               StartDate = GetPastDays(p.StartDate, today),
    11.            };
    12. 
    13.            grid.DataSource = query;
    14. 
    15.            if (grid.Rows.Any())
    16.            {
    17.                grid.Select();
    18.                grid.Rows.Last().IsCurrent = true;
    19.                grid.TableElement.ScrollToRow(grid.Rows.First());
    20.            }

    How can I solve the issue?

  7. Joe
    Joe avatar
    26 posts
    Member since:
    Feb 2012

    Posted 11 Aug in reply to Mohsen Link to this post

    I am sure somebody else can have a more elegant solution, but what I have done in the past is to either:

    1. update the underlying database.  If you do that then you refresh the grid after the data is updated and it should reflect the new data.

    2. add a column to the grid that is a unbound column, then your code from before should update that column.  This is what I have done normally, sometimes even hiding the databound column and only showing the new column I created.

    If you create the grid ahead of time and use field names then you should be able to modify your select new part to use those names and it will populate it.

    IE: make sure your grids fields are Id, Title, Code, StartDate and whatever unbound ones you want.

    Joe

     

  8. Joe
    Joe avatar
    26 posts
    Member since:
    Feb 2012

    Posted 11 Aug in reply to Joe Link to this post

    A correction (I HATE that you can't modify posts here!)

    When I said: "...should be able to modify your select new part to use those names and it will populate it" -- ignore the modify part, your select statement is fine I think.

    Just go into your grid properties and make sure that you add the columns ahead of time vs letting it automaticly create them and set each ones field property to the field name.

  9. Mohsen
    Mohsen avatar
    4 posts
    Member since:
    Aug 2016

    Posted 11 Aug in reply to Joe Link to this post

    I don't agree with you. Your solution is not logical and is so complex. I want admins of this forum to help me.
  10. Joe
    Joe avatar
    26 posts
    Member since:
    Feb 2012

    Posted 11 Aug in reply to Mohsen Link to this post

    Like I said, I am sure somebody else will have a more elegant solution.

    My solution is simply what I have used and have working on multiple projects.

    Good luck, maybe you should consider paying for support and opening a trouble ticket - they are very good at responding.

    I do wonder however, what is so complex or 'not logical' about "update your underlying data source then refresh the grid"?

     

  11. Hristo Merdjanov
    Admin
    Hristo Merdjanov avatar
    710 posts

    Posted 15 Aug Link to this post

    Hi guys,

    Thank you for writing.

    Mohsen, the code snippet showing how you are binding the grid indicates that you are actually binding it to a collection of anonymous types. In this scenario, the grid binds successfully, however, it cannot be edited. Exactly the same behavior is observed with the standard MS grid. You can check the following thread discussing the same question: http://www.telerik.com/forums/problem-while-updating-the-cell-from-item-template-of-herarchical-grid.

    As a solution, I can suggest creating a simple class having all the properties you want and use it in your query: http://stackoverflow.com/questions/534690/return-anonymous-type-results.

    I hope this helps. Should you have further questions please do not hesitate to write back.

    Regards,
    Hristo Merdjanov
    Telerik by Progress
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms. For more information check out this blog post and share your thoughts.
Back to Top
UI for WinForms is Visual Studio 2017 Ready