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