When I have only 1 result in a grid, and I try to programmatically select that row it does not set the SelectedRows or associated properties.
I select the newrow from the gridview's Rows collection. I see that I have a valid newrow. CurrentRow is null before I set it to newrow, and gets set properly, but the SelectionChanged event doesn't fire. And if you look at SelectedRows it has a count of 0, even though CurrentRow is properly set. If I have 2 or more records it works fine. It seems to me that the first row in Rows is considered selected by default, and so it's not registering a change. But at the very least SelectedRows should be set when I assign newrow.
var newrow = CurrentOrdersGridView.Rows.Where(o => ((TDOC2.UIFunctions.ORDER.OrderSearchResult)o.DataBoundItem).PRI == oldpri).FirstOrDefault();
if
(newrow !=
null
)
{
CurrentOrdersGridView.CurrentRow = newrow;
}
I select the newrow from the gridview's Rows collection. I see that I have a valid newrow. CurrentRow is null before I set it to newrow, and gets set properly, but the SelectionChanged event doesn't fire. And if you look at SelectedRows it has a count of 0, even though CurrentRow is properly set. If I have 2 or more records it works fine. It seems to me that the first row in Rows is considered selected by default, and so it's not registering a change. But at the very least SelectedRows should be set when I assign newrow.
6 Answers, 1 is accepted
0
Ebrahim
Top achievements
Rank 1
answered on 15 Jan 2012, 02:16 PM
Hi Eric,
Try this.
Regards,
Ahmed
Try this.
this
.CurrentOrdersGridView.CurrentRow =
this
.CurrentOrdersGridView.Rows[0];
Regards,
Ahmed
0
Eric
Top achievements
Rank 1
answered on 16 Jan 2012, 02:12 PM
Thank you for the suggestion but explicitly setting it to row 0 results in the same behavior as assigning the one I select with the Where clause.
It would be nice to have an elegant solution to this. I ended up making a really ugly work around that involves checking Rows.Count == 1, and if it is then it explicitly calls a new, overridden version of my event handler which takes the row itself as a parameter (since I can't just select the row from SelectedRows). Not elegant, but it works.
It would be nice to have an elegant solution to this. I ended up making a really ugly work around that involves checking Rows.Count == 1, and if it is then it explicitly calls a new, overridden version of my event handler which takes the row itself as a parameter (since I can't just select the row from SelectedRows). Not elegant, but it works.
0
Accepted
Hello Eric,
This appears to be an issue. When CurrentRow is set to null and you change its value, the new current row is not being selected. I logged it in our issue tracking system and it will be addressed in one of our upcoming releases. I updated also your Telerik points for bringing our attention to this issue.
You can work around it by setting the IsSelected property of GridViewRowInfo. Here is a sample:
If you have more questions, do not hesitate to contact us.
Kind regards,
Jack
the Telerik team
This appears to be an issue. When CurrentRow is set to null and you change its value, the new current row is not being selected. I logged it in our issue tracking system and it will be addressed in one of our upcoming releases. I updated also your Telerik points for bringing our attention to this issue.
You can work around it by setting the IsSelected property of GridViewRowInfo. Here is a sample:
this
.radGridView1.CurrentRow =
this
.radGridView1.Rows[0];
if
(
this
.radGridView1.CurrentRow !=
null
)
{
this
.radGridView1.CurrentRow.IsSelected =
true
;
}
If you have more questions, do not hesitate to contact us.
Kind regards,
Jack
the Telerik team
SP1 of Q3’11 of RadControls for WinForms is available for download (see what's new).
0
Eric
Top achievements
Rank 1
answered on 17 Jan 2012, 02:18 PM
Thank you for your response. Setting IsSelected on CurrentRow does give the desired behavior, and looks nicer than what I was doing.
0
Ales
Top achievements
Rank 1
answered on 28 Jun 2012, 03:27 PM
Hi Mr,
i have used the implementation, but its not working..see picture..why is after setting rowIndex 8 currentrow index = 1 ?
Thanks for You answer
AB
i have used the implementation, but its not working..see picture..why is after setting rowIndex 8 currentrow index = 1 ?
Thanks for You answer
AB
0
Hi Ales,
The Rows collection in RadGridView contains all rows in the order in which they appear in the original data source. In this case you should use the ChildRows collection which represents the rows the same way as they appear in RadGridView after applying filtering, grouping or sorting.
If you need further assistance, do not hesitate to contact us.
Greetings,
Jack
the Telerik team
The Rows collection in RadGridView contains all rows in the order in which they appear in the original data source. In this case you should use the ChildRows collection which represents the rows the same way as they appear in RadGridView after applying filtering, grouping or sorting.
If you need further assistance, do not hesitate to contact us.
Greetings,
Jack
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>