getting current row value while filtering on

7 posts, 1 answers
  1. Suren
    Suren avatar
    12 posts
    Member since:
    Jul 2012

    Posted 08 Jul 2012 Link to this post

    hi guys,
    i don't know whether its a bug or i'm accessing it wrong , that's why i came here to get some help from the experts.

    in radgridview a set of data is loaded using dataset, so when some clicks on the row it will display the row values in a label above.
    so what i have done is working 100% untill i do the following, if i use the gridview's bulit in filtering option and filter the results , i'm getting the value of some other row , i have attached a screenshot. as u can see in it somerow is selected but it's displaying someother row name in the textbox above, here is the code i use, i use VC# 2010 with rad Q2 2012.

    private void radGridView1_CurrentRowChanged(object sender, CurrentRowChangedEventArgs e){
     txt_Name.Text = radGridView1.Rows[radGridView1.CurrentCell.RowIndex].Cells["NAME"].Value.ToString();
    }

    please let me know  if u need more info

    thanks suren
  2. Answer
    Stefan
    Admin
    Stefan avatar
    2908 posts

    Posted 10 Jul 2012 Link to this post

    Hi Suren,

    Thank you for writing.

    When some data operation is applied to RadGridView (filtering, grouping, etc) the result of this operation is stored in the ChildRows collection of the control, not the Rows collection. In your example you are using index and you are accessing the row in the wrong collection, thus the observed behavior. Detailed explanation of both collections can be found here: http://www.telerik.com/help/winforms/gridview-rows-rows-vs-childrows.html.

    Here is a code that will always work, since you will not depend on a row index:
    void radGridView1_CurrentRowChanged(object sender, CurrentRowChangedEventArgs e)
    {
        if (e.CurrentRow.Cells["Name"].Value != null)
        {
            this.Text = e.CurrentRow.Cells["Name"].Value.ToString();
        }
    }

    I hope this helps.
     
    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 >>
  3. Suren
    Suren avatar
    12 posts
    Member since:
    Jul 2012

    Posted 12 Jul 2012 Link to this post

    Hello,
    it works,
    thank you very much for solving my problem
  4. Stefan
    Admin
    Stefan avatar
    2908 posts

    Posted 16 Jul 2012 Link to this post

    You are welcome.

    Regards,
    Stefan
    the Telerik team
    RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
  5. Brendan
    Brendan avatar
    63 posts
    Member since:
    Dec 2011

    Posted 19 Nov 2014 in reply to Stefan Link to this post

    I wanted to see if there was some way to simplify finding the current, selected row when filtered.  In short, I want to get the value of a cell from a contextmenuopening event

    I have many grids that will call the same context menu, customized by the calling control, and simply want to get a cell value based on the current row, filtered or unfiltered.  Here is some code and an illustration.

    The attached image shows a context menu where I need to get the value of a column for the selected row.  Can this be simplified or determined by using the child row? 

    Thanks

    'this creates the context menu custom for the form/grid
    Private Sub grdMain_ContextMenuOpening(sender As Object, e As Telerik.WinControls.UI.ContextMenuOpeningEventArgs) Handles grdMain.ContextMenuOpening
            Try
                frm_CvBase.pBuildRightMenuCV(Me, grdMain)
                e.ContextMenu = frm_CvBase.mnuCVMainGrid.DropDown
            Catch ex As Exception
                pErrorMsgBox(ex)
            End Try
    End Sub
     
    Private Sub mnuCvContext_Click    'handles all context menu clicks
    ....
    'get the value of the current row based on a given column (data driven)
    sCellValue = grdMain.Rows(grdMain.CurrentRow.Index).Cells(col.Index).Value.ToString.Trim
     
    'this works unfiltered, not filtered - as I know.
    'Is there a simple way to get the 'current' row WITHOUT adding code to a CurrentRowChanged event for every grid?
  6. Stefan
    Admin
    Stefan avatar
    2908 posts

    Posted 20 Nov 2014 Link to this post

    Hi Brendan,

    I can see you have access to your grid, so you could just use the CurrentCell.Value property:
    grdMain.CurrentCell.Value

    Let me know how this works for you.

    Regards,
    Stefan
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  7. Brendan
    Brendan avatar
    63 posts
    Member since:
    Dec 2011

    Posted 21 Nov 2014 in reply to Stefan Link to this post

    Thanks Stefan, that did the trick!  And it couldn't have been simpler :-)
Back to Top