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

getting current row value while filtering on

6 Answers 391 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Suren
Top achievements
Rank 1
Suren asked on 08 Jul 2012, 06:45 PM
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

6 Answers, 1 is accepted

Sort by
0
Accepted
Stefan
Telerik team
answered on 10 Jul 2012, 01:58 PM
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 >>
0
Suren
Top achievements
Rank 1
answered on 12 Jul 2012, 06:20 AM
Hello,
it works,
thank you very much for solving my problem
0
Stefan
Telerik team
answered on 16 Jul 2012, 11:27 AM
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 >>
0
Brendan
Top achievements
Rank 1
answered on 19 Nov 2014, 06:33 PM
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?
0
Stefan
Telerik team
answered on 20 Nov 2014, 08:44 AM
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.

 
0
Brendan
Top achievements
Rank 1
answered on 21 Nov 2014, 09:11 PM
Thanks Stefan, that did the trick!  And it couldn't have been simpler :-)
Tags
GridView
Asked by
Suren
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Suren
Top achievements
Rank 1
Brendan
Top achievements
Rank 1
Share this question
or