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

Get cell value

3 Answers 382 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Ilan
Top achievements
Rank 1
Ilan asked on 14 Jun 2009, 03:45 PM
What are all the ways to programmatically get cell value? 

3 Answers, 1 is accepted

Sort by
0
Milan
Telerik team
answered on 15 Jun 2009, 06:34 AM
Hello Ilan,

You can create a simple method like this one:

 public object GetCellValue(GridViewDataControl gridView, int rowIndex, int cellIndex)    
{    
    var row = gridView.ItemsControl.ItemsGenerator.GenerateItemAtIndex(rowIndex) as GridViewRow;    
    object cellValue = null;    
    
    if (row != null && row.Cells.Count >= cellIndex)    
        cellValue = row.Cells[cellIndex].Content;    
    
    return cellValue;    

.. and then use it like this:

var myValue = this.GetCellValue(this.RadGridView1, 1, 0); 

Unfortunately you will only be able to use this method for cells and rows that are visible.

Greetings,
Milan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
gaurav
Top achievements
Rank 1
answered on 08 Aug 2019, 08:27 PM

 

 

I have this event handler which is called when on event RowEditEnded="radGridView_EditComments"

Here is what I have in the method 

 public void radGridView_EditComments(object sender, GridViewRowEditEndedEventArgs e) 
        { 
            if (e.EditAction == GridViewEditAction.Cancel) 
            { 
                return; 
            } 
            if (e.EditOperationType == GridViewEditOperationType.Edit) 
            {
                clsDiagnosticsMessageList obj = new clsDiagnosticsMessageList();
                clsDiagnosticsMessageList obj1 = e.Row.Cells[4].Value;             
               
            } 
        }

The problem is that i cannot access the cell value using the above line which is in bold and I am getting the following error:

GridViewCellBase' does not contain a definition for 'Value' and no accessible extension method 'Value' accepting a first argument of type 'GridViewCellBase' could be found (are you missing a using directive or an assembly reference?
Can you tell me what is the correct way to extract a particular cell value?

0
Dinko
Telerik team
answered on 13 Aug 2019, 11:38 AM
Hi gaurav,

Thank you for the provided code snippet.

The cells collection property of the e.Row is an IList of GridViewBaseCell which does not contain such property (Value). You need to cast the e.Row.Cells[4] to GridViewCell and then you can use the Value property to get the content of a specific cell. 
public void radGridView_EditComments(object sender, GridViewRowEditEndedEventArgs e)
{
    if (e.EditAction == GridViewEditAction.Cancel)
    {
        return;
    }
    if (e.EditOperationType == GridViewEditOperationType.Edit)
    {
        clsDiagnosticsMessageList obj = new clsDiagnosticsMessageList();
        clsDiagnosticsMessageList obj1 = (e.Row.Cells[4] as GridViewCell).Value;
    }
}

Give this approach a try and let me know if further questions arise.

Regards,
Dinko
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
GridView
Asked by
Ilan
Top achievements
Rank 1
Answers by
Milan
Telerik team
gaurav
Top achievements
Rank 1
Dinko
Telerik team
Share this question
or