This is a migrated thread and some comments may be shown as answers.

Update of text/value on NewRow at CellEndEdit event does not reflect changes

9 Answers 709 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jack
Top achievements
Rank 1
Jack asked on 24 Oct 2008, 02:24 PM
Dear Telerik team,


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

Sort by
0
Nick
Telerik team
answered on 27 Oct 2008, 11:28 AM
Hello Jack,

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.
0
Jack
Top achievements
Rank 1
answered on 28 Oct 2008, 09:07 AM
Thanks for the help and info.

Kind regards,

JAck
0
Jack
Top achievements
Rank 1
answered on 31 Oct 2008, 05:09 PM
Hi Nick,

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
0
Nick
Telerik team
answered on 04 Nov 2008, 08:18 AM
Hello 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.
0
Jack
Top achievements
Rank 1
answered on 04 Nov 2008, 03:56 PM
Hello Nick,


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
0
Jack
Top achievements
Rank 1
answered on 04 Nov 2008, 03:56 PM
Hello Nick,


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
0
Jack
Top achievements
Rank 1
answered on 07 Nov 2008, 08:38 AM
Hello Nick / Telerik,


An answer to my latest quesion would be nice.


Kind regards,

Jack
0
Accepted
Nick
Telerik team
answered on 07 Nov 2008, 01:43 PM
Hi 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.
0
Jack
Top achievements
Rank 1
answered on 12 Nov 2008, 11:25 AM
Hello Nick,

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

 

Tags
GridView
Asked by
Jack
Top achievements
Rank 1
Answers by
Nick
Telerik team
Jack
Top achievements
Rank 1
Share this question
or