9 Answers, 1 is accepted
var firstRow = (GridViewRow)this.RadGridView1.ItemsControl.ItemsGenerator.GenerateItemAtIndex(0);
GridViewCell firstCell = (GridViewCell)firstRow.Items[0];
but radgirdview is fail
Generally it is not recommended to work with the visual elements. Since the RadGridView supports UI Virtualization, its rows/cells are reused and that is why we cannot rely on the visual elements.
You could iterate trough the Items and Columns collections of the RadGridView instead.
Didie
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
Can you give some example code?I have not any idea!!
You could iterate through the collections like so:
foreach
(Club club
in
this
.clubsGrid.Items)
{
// work with the 'club' data item;
}
foreach
(GridViewColumn column
in
this
.clubsGrid.Columns)
{
// work with each column
}
You could access the clubsGrid.Columns[1] directly. For more details on working with the GridView, I would recommend you to check our online documentation.
All the best,
Didie
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
You cannot access the cell value displayed in the RadGridView using indexes. What I am suggesting is to work with the data elements instead. Is your second column column bound to a property of the business object?
For example lets say the business object is of type Club and it has properties Name and Established. You have bound the first column to the "Name" property, the second column to the "Established" property.
Then you could access the second row and second column like so:
(radgridview.Items[1] as Club).Established
May I ask you why do you need this value? Based on your goal I would suggest you a better solution.
Didie
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
radgridview.Itemsoure=e.result(this code is from another web page,but radgridview is in my page ) ;
I don't know how many columns and rows until I see the radgirdview , (e.result is from wcf's result and I don't know much about it);I
I just want to screen and select some data in radgridview's datasoure,not all.
You could get the cell which is in the second row and the column "Age" like so:
GridViewRow row =
this
.clubsGrid.GetRowForItem(
this
.clubsGrid.Items[1]);
var cell =row.Cells.OfType<GridViewCell>().Where(c => c.Column.Header !=
null
? c.Column.Header.ToString() ==
"Age"
:
false
).First();
All the best,
Didie
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.