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"?

10 posts, 0 answers
  1. PEIYANG
    PEIYANG avatar
    65 posts
    Member since:
    Jul 2012

    Posted 16 Jul 2012 Link to this post

    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"?
  2. PEIYANG
    PEIYANG avatar
    65 posts
    Member since:
    Jul 2012

    Posted 16 Jul 2012 Link to this post

    this is the gridview:
    var firstRow = (GridViewRow)this.RadGridView1.ItemsControl.ItemsGenerator.GenerateItemAtIndex(0);
    GridViewCell firstCell = (GridViewCell)firstRow.Items[0];
    but radgirdview is fail
  3. DevCraft banner
  4. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 17 Jul 2012 Link to this post

    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.

  5. PEIYANG
    PEIYANG avatar
    65 posts
    Member since:
    Jul 2012

    Posted 17 Jul 2012 Link to this post

    iterate trough the Items and Columns collections??
    Can you give some example code?I have not any idea!!
  6. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 17 Jul 2012 Link to this post

    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.

  7. PEIYANG
    PEIYANG avatar
    65 posts
    Member since:
    Jul 2012

    Posted 17 Jul 2012 Link to this post

    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??
  8. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 18 Jul 2012 Link to this post

    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.

  9. PEIYANG
    PEIYANG avatar
    65 posts
    Member since:
    Jul 2012

    Posted 18 Jul 2012 Link to this post

    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.
  10. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 23 Jul 2012 Link to this post

    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.

  11. Srinivas
    Srinivas avatar
    4 posts
    Member since:
    Oct 2013

    Posted 20 Dec 2013 Link to this post

       Hi,
         Here(In Below file) Half of the Email ID is Hiding, I want to display extra email id in next line..

    Thanks..

Back to Top
DevCraft banner