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

access a row cell as GridDataCellElement

6 Answers 815 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Naser
Top achievements
Rank 1
Naser asked on 24 Aug 2012, 11:27 AM
Hi.
I need to access gridview row' cells as GridDataCellElement. is there any way. I want to read text of the cell (formatted value) .

6 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 29 Aug 2012, 05:53 AM
Hello Naser,

Thank you for writing.

There is a way to access the visual cell elements by using the GetCellElement method of the TableElement. Please note that, using the visual cells is usually not recommended because the visual cells are being reused by the UI virtualization of the grid and you can easily end up reading incorrect cell value.

I hope this helps.
 
Greetings,
Stefan
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
0
Naser
Top achievements
Rank 1
answered on 05 Sep 2012, 06:37 PM
Hi.
I have a method that must return a GridViewCellInfo parameter text. how can I do it.

public static string GetRadCellText(GridViewCellInfo gridViewCellInfo)
{
//TO DO : here must be a code that return text of cell
}


0
Accepted
Stefan
Telerik team
answered on 07 Sep 2012, 10:44 AM
Hello Naser,

Here are two possible implementations depending for a scenario where you modify the cell text and where you do not modify the cell text:
public string GetRadCellText(GridViewCellInfo gridViewCellInfo)
{
    return gridViewCellInfo.Value.ToString(); //if not modified the value will be the same as the text
    //or
    GridCellElement cellElement = radGridView1.TableElement.GetCellElement(gridViewCellInfo.RowInfo, gridViewCellInfo.ColumnInfo);
    return cellElement.Text; //this returns the cell text (if it is modified in the cell formatting event it will not equal the cell value)
}

I hope this helps.
 
Regards,
Stefan
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
0
Naser
Top achievements
Rank 1
answered on 07 Sep 2012, 05:17 PM
Thanks you,
 I need and tested second way, but
 radGridView1.TableElement.GetCellElement(gridViewCellInfo.RowInfo, gridViewCellInfo.ColumnInfo);
get a null value , so I can't got text of cellElement.


0
Accepted
Stefan
Telerik team
answered on 10 Sep 2012, 01:47 PM
Hi Naser,

As GridCellElement is a visual element, you should pass a reference to a visible cell to make sure that the method will return correct results.

Could you please provide me with a small sample of your project and let me know what are your exact requirements so I can point you to the right direction.
 
All the best,
Stefan
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
0
Naser
Top achievements
Rank 1
answered on 10 Sep 2012, 05:33 PM
Hi.
Thank you very much. 
your answer ( 
GridCellElement cellElement = radGridView1.TableElement.GetCellElement(gridViewCellInfo.RowInfo, gridViewCellInfo.ColumnInfo);
    return cellElement.Text; )

was correct.
Tags
GridView
Asked by
Naser
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Naser
Top achievements
Rank 1
Share this question
or