I want to implement my own version of load on demand feature for RadCheckedDropDownList (if there's already one that meets my requirements then sorry for posting).
When the RadCheckedDropDownList's OnKeyUp event happens for alphanumeric char I want to send async request to my ASP.NET Web Service - when webservice's request is completed I want to either (both options are viable for me):
a) add new items (that are not already existing) to the DataSource,
b) save somewhere items that are already checked and load items to the DataSource,
and show Popup scrolled to the item that is matching the text that already user inserted into RadCheckedDropDownList's RadCheckedDropDownListEditableAreaElement.
My code so far:
private void LoadOnDemandCompleted( object sender, GetDropDownMenuItemsPagedCompletedEventArgs e )
{
//RadCheckedDropDownListOnDemand - my class that inherits RadCheckedDropDownList
if ( e.Error != null || e.Result == null || (int)e.UserState != this.RadCheckedDropDownListOnDemand.RequestId )
{
//WS call errored out, nothing was returned, or the request number is not matching
return;
}
if ( !( this.RadCheckedDropDownListOnDemand.DataSource is List<RadCheckedListDataItem> mainDataSource ) )
return;
//Properties explanation:
//Value == string to display
//Id == id in database
//ChoiceOrder - order in which the RadCheckedListDataItem should appear -> lower ChoiceOrder means it is higher on the list
var itemsFiltered = e.Result.Select( re => new RadCheckedListDataItem( re.Value )
{
Value = re.Id,
Tag = re.ChoiceOrder,
} )
.Where( item => !mainDataSource.Any( mainDataSourceItem => (int)item.Value == (int)mainDataSourceItem.Value ) )
.ToList();
//don not want to add items that are already existing in
if ( itemsFiltered.Count > 0 )
{
mainDataSource.AddRange( itemsFiltered );
//want to refresh item list for CheckedDropDownListElement
if ( !( this.RadCheckedDropDownListOnDemand.CheckedDropDownListElement.DataSource is List<RadCheckedListDataItem> listElementDataSource ) )
return;
listElementDataSource.AddRange( itemsFiltered );
//this does not show the newly added items
this.RadCheckedDropDownListOnDemand.CheckedDropDownListElement.ShowPopup();
}
}