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

how to get radgridview's cell which is in the second row and second column? And how to get radgridview's column which head name is "age"?

9 Answers 200 Views
GridView
This is a migrated thread and some comments may be shown as answers.
PEIYANG
Top achievements
Rank 1
PEIYANG asked on 17 Jul 2012, 01:36 AM
how to get radgridview's cell which is in the second row and second  column? And how to get radgridview's column which head name is "age"?

9 Answers, 1 is accepted

Sort by
0
PEIYANG
Top achievements
Rank 1
answered on 17 Jul 2012, 01:48 AM
this is the gridview:
var firstRow = (GridViewRow)this.RadGridView1.ItemsControl.ItemsGenerator.GenerateItemAtIndex(0);
GridViewCell firstCell = (GridViewCell)firstRow.Items[0];
but radgirdview is fail
0
Dimitrina
Telerik team
answered on 17 Jul 2012, 12:01 PM
Hello,

 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.

Kind regards,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
PEIYANG
Top achievements
Rank 1
answered on 17 Jul 2012, 02:10 PM
iterate trough the Items and Columns collections´╝č´╝č
Can you give some example code?I have not any idea!!
0
Dimitrina
Telerik team
answered on 17 Jul 2012, 03:13 PM
Hello,

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.

0
PEIYANG
Top achievements
Rank 1
answered on 17 Jul 2012, 03:52 PM
Thank you above.I read the document about 30 minutes,but I still don't know how to get radgridview's cell which is in the second row and second column! radgridview.Columns[1][1] seems wrong??
0
Dimitrina
Telerik team
answered on 18 Jul 2012, 06:00 AM
Hi,

 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.

Regards,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
PEIYANG
Top achievements
Rank 1
answered on 18 Jul 2012, 08:41 AM
in my code ,somebody use itemsource to show the data(they seems use mvvm):
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.
0
Dimitrina
Telerik team
answered on 23 Jul 2012, 06:34 AM
Hi,

 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.

0
Srinivas
Top achievements
Rank 1
answered on 20 Dec 2013, 10:51 AM
   Hi,
     Here(In Below file) Half of the Email ID is Hiding, I want to display extra email id in next line..

Thanks..

Tags
GridView
Asked by
PEIYANG
Top achievements
Rank 1
Answers by
PEIYANG
Top achievements
Rank 1
Dimitrina
Telerik team
Srinivas
Top achievements
Rank 1
Share this question
or