9 Answers, 1 is accepted
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"
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?
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.
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?
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
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.
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"?
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