I have an event handle on the RadGridView.CellEndEdit event;
Its purpose is to look up a value from the database by the value entered in that cell and overwrite it with the value returned from the database.
Scenario and implementation:
User creates a new row in the grid and enters 'ABC' as value for the 1st column//cell. Then they press ENTER which will cause the radGridView1_CellEndEdit to be invoked.
private void radGridView1_CellEndEdit(object sender, GridViewCellEventArgs e)
{
int rowIndex = e.RowIndex; //is -1, since it's a new row
int columnIndex = e.ColumnIndex; //is 0, since it's the 1st column that's being editited by the user.
GridViewRowInfo row = this.radGridView1.MasterGridViewInfo.CurrentRow; //The only way to get the row (since rowindex => -1)
string cellText = row.Cells[0].CellElement.Text; //is 'ABC', as entered by the user
string cellValue = (string)row.Cells[0].Value; /is <Null> ??????
row.Cells[0].Text = string.Join(",", new string[] { cellText, cellText }); //Concatenats into 'ABC,ABC' and overwites the cells text with that.
}
Now when you look at the cell on screen, you'll see that it still presenting it as 'ABC'.
Remarks.
1) Setting the Cell value does not help in any way.
2) The code above does work if the row is not a new row.
3) If the grid is under VirtualMode = true, then NO text can be read from that cell in the snippet.
I would like to know what is there to do to have the value/text being overwitten on CellEndEdit' in case of a NEW row. It's a key requirement for the application I'm working on.
Kind regards,
Jack
9 Answers, 1 is accepted
Thank you for contacting us.
Please see the sample code below for questions 1) and 2):
private void radGridView1_CellEndEdit(object sender, Telerik.WinControls.UI.GridViewCellEventArgs e) |
{ |
if (this.radGridView1.CurrentCell.RowIndex < 0) //new row |
{ |
string s = this.radGridView1.CurrentCell.Value.ToString(); //current value |
this.radGridView1.CurrentCell.Value = s + "sadf"; //setting new value |
} |
Console.WriteLine (this.radGridView1.CurrentCell.RowIndex); //row index |
Console.WriteLine(this.radGridView1.CurrentCell.ColumnIndex); //column index |
} |
If you want to use Virtual mode you should use CellValuePushed event, but unfortunately there is glitch there which is to be fixed in one of our future releases. I can assure you that it is a high priority.
Do not hesitate to contact me back if you have more questions.
All the best,
Nick
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Kind regards,
JAck
Another question regarding the one I've asked in this topic.
How to set value in a different cell than the Grid.CurrentCell of the same Grid.CurrentRow?
I want to update the current cell being edited, and some of the other cells on the same row ... Updating the current cell works......but not the other cells.
Kind regards and awaiting your answer,
Jack
Thank you for your question.
Please see the following code snippet:
this.radGridView1.Rows[0].Cells[0].Value = "new value"; |
this.radGridView1.Rows[0].Cells[1].Value = 60; |
Do not hesitate to write me back if you have further questions.
Best wishes,
Nick
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Your solution only works for the first new item being added.
When you enter a second new row, its (in my case column[3]) cell value is not reflected onto the grid as described previously.
Please don't hesitate to give a definite solving answer ;-)
Kind regards,
Jack
Your solution only works for the first new item being added.
When you enter a second new row, its (in my case column[3]) cell value is not reflected onto the grid as described previously.
Please don't hesitate to give a definite solving answer ;-)
Kind regards,
Jack
An answer to my latest quesion would be nice.
Kind regards,
Jack
Thank you for contacting me back.
There is no straightforward way to modify another cell in the new row besides the currently edited one, but there is a workaround using Rows.Count property:
private void radGridView1_CellEndEdit(object sender, Telerik.WinControls.UI.GridViewCellEventArgs e) |
{ |
if (this.radGridView1.CurrentCell.RowIndex < 0) //new row |
{ |
string s = this.radGridView1.CurrentCell.Value.ToString(); //current value |
this.radGridView1.CurrentCell.Value = s + "sadf"; //setting new value |
this.radGridView1.Rows[this.radGridView1.Rows.Count - 1].Cells[1].Value = "asdf"; |
} |
} |
Do not hesitate to write me back if have more questions.
All the best,
Nick
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Here the solution as i have implemented (using your answers)
private void UpdateRowValueWithArticleValues(ArticleUnloadableInfo articleInfo, GridViewRowInfo row)
{
GridViewCellInfoCollection rowCells = row.Cells;
GridViewDataRowInfo dataRow = null;
string articleName = (articleInfo != null) ? articleInfo.Name : null;
int? quantityInStock = (articleInfo != null) ? (int?)articleInfo.QuantityInStock : null;
if (this.radGridView1.CurrentCell.RowIndex < 0) //new row
{
this.radGridView1.Rows[this.radGridView1.Rows.Count - 1].Cells[3].Value = articleName;
this.radGridView1.Rows[this.radGridView1.Rows.Count - 1].Cells[4].Value = quantityInStock;
}
else
{
dataRow = (
GridViewDataRowInfo)row;
dataRow.Cells[3].Value = articleName;
dataRow.Cells[4].Value = quantityInStock;
}
}
where the Row parameter passed is passed from the EndCellEdit
row =
this.radGridView1.CurrentRow;
and the ArticleInfo passed is a custom object that holds some looked up values i want to write into the current edited row.
Kind regards,
Jack