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

Get cell value

3 Answers 1221 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.
nwenar
Top achievements
Rank 1
commented on 24 Dec 2022, 08:32 AM

How Can I do the same for UWP Rad Data Grid?

 

Martin Ivanov
Telerik team
commented on 28 Dec 2022, 08:49 AM

Hey nwenar, can you please post your question in the UWP forum?
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 | Tech Support Engineer
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 | Tech Support Engineer
Telerik team
Share this question
or