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

Changing selectedindex from within selectedindexchanged event

1 Answer 228 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Thomas
Top achievements
Rank 1
Thomas asked on 27 Mar 2013, 09:15 PM
When I am within a selectedindexchanged event of a listcontrol and I try to programmatically change the selectedindex value, the change does not take.  The concept is that "new" is the first item in the list and when "new" is selected an actual new record is inserted into the listcontrol and I want to position the selection to the new item.  The command does not error but the selectedindex does not change either.  This is also the case if you try to change it from the debugger.  Any suggestions on how to accomplish this?

1 Answer, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 01 Apr 2013, 12:55 PM
Hello Thomas,

Thank you for writing.

RadListControl/RadDropDownList 
does not support changing the SelectedIndex in the SelectedIndexChangedEventHowever, you can try to clear the SelectedItems and set the DataLayer's CurrentPossition to the desired index in the SelectedIndexChanged. 

Please, refer to the code below:
private void radListControl_SelectedIndexChanged(object sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e)
{
           ((RadListDataItemSelectedCollection)this.radListControl1.SelectedItems).Clear();
           this.radListControl1.ListElement.DataLayer.CurrentPosition = 5;
           this.radListControl1.Items[5].Selected = true;
           this.radListControl1.Items[5].Active = true;
}

Please bear in mind that this scenario is not supported and we do not guarantee that this workaround will work correctly in all cases.

Should you have any other questions, do not hesitate to contact us. All the best,
Peter
the Telerik team
WinForms Q1 2013 boasts PivotGrid, PDF Viewer, Chart enhancements and more. Check out all of the latest highlights.
Tags
ListView
Asked by
Thomas
Top achievements
Rank 1
Answers by
Peter
Telerik team
Share this question
or