13 Answers, 1 is accepted
Thank you for writing.
This behavior is by design. We decided to change the current position of the currency manager when the item at the current position was deselected in order to avoid the case in which the current position points to an item that is not selected. Is this behavior inconvenient? If it is please explain in more detail what your goal is and we will consider providing a way to modify this behavior.
I am looking forward to your reply.
Greetings,
Victor
the Telerik team
Thank you for clarifying.
The point of SelectedIndexChanged is that only one of the selected items has the current index. When you deselect an item different than the one with the current index, SelectedIndexChanged will not fire. This is semantically correct, the Microsoft ListBox control fires SelectedIndexChanged every time you select something, event if it is the same item. In order to listen for when an Item's Selected state changes you have to subscribe to RadListControl's DataItemPropertyChanged event. This event is not yet available but will be available in the Q2 service pack. It will provide information about which item changed and what the new and old values are.
I would like to thank you for your invaluable feedback on the list control. Your Telerik points have been updated.
Sincerely yours,
Victor
the Telerik team
I have just loaded SP1 as the release history states that the DataItemPropertyChanged event is now available. Is there some sample code to show how to use the DataItemPropertyChanged event as I cannot see it to add to my control in the VS2008 designer?
Thank you for writing.
Please refer to the following snippet:
void
ListElement_DataItemPropertyChanged(
object
sender, RadPropertyChangedEventArgs e)
{
if
(e.Property == RadListDataItem.SelectedProperty)
{
bool
newVal = (
bool
)e.NewValue;
// do something with the new value.
}
}
Subscribing to this event looks like so:
this
.radListControl1.ListElement.DataItemPropertyChanged +=
new
RadPropertyChangedEventHandler(ListElement_DataItemPropertyChanged);
this
.radDropDownList1.ListElement.DataItemPropertyChanged +=
new
RadPropertyChangedEventHandler(ListElement_DataItemPropertyChanged);
Please write again if you need further assistance. Sincerely yours,
Victor
the Telerik team
I have same issue with selecting an item in ListControl. But the DataItemPropertyChanged Event is not a solution for me, because it fires to often and I didn't find an easy way to fire it programmatically.
Maybe you can tell me another solution for this.
Thanks!
Kind regards
Juergen
Thank you for contacting us.
Could please explain your scenario in greater detail? I am not sure that I understand the meaning of 'firing an event programmatically'. This information will allow me to assist you further.
I looking forward for your reply.
Peter
the Telerik team
Thanks for your answer.
Here is my scenario:
I have multiple listcontrols (with multiselection enabled) and a method which gets a RadListDataItem. So I get to know which Item was last selected I have to store it in a reference. This is easy done by using selectedIndexChanged or selectedItemChanged Events but as I do a right click (for conextmenu) no event is fired. So I have to use the MouseDown event and check which button was pressed (in fact of multiselection) and select the Item. But as I set SelectedItem no event is fired, if the item was even selected before.
Hope my english is not to bad and you understand my explanation.
best regards,
Juergen
I just want to confirm what you are trying to do. Is it correct to say that when you right click on one of the data items in your RadListBox, you wish for that item to become selected or deselected?
Richard
Thank you for the clarification.
In case that you want to know when RadListDataItem is selected or unselected, I recommend selecting/unselecting an item by setting the value of Selected property and subscribe to the DataItemPropertyChanged event.
Setting the value of the Selected property will always fire the DataItemPropertyChanged event.
Please refer to the code snippet below:
private
void
Form1_Load(
object
sender, EventArgs e)
{
this
.radListControl1.SelectionMode = SelectionMode.MultiSimple;
this
.radListControl1.ListElement.DataItemPropertyChanged +=
new
Telerik.WinControls.RadPropertyChangedEventHandler(ListElement_DataItemPropertyChanged);
}
RadListDataItem lastSelected =
null
;
void
ListElement_DataItemPropertyChanged(
object
sender, Telerik.WinControls.RadPropertyChangedEventArgs e)
{
if
(e.Property != RadListDataItem.SelectedProperty)
{
return
;
}
RadListDataItem checkedItem = (RadListDataItem)sender;
bool
isChecked = (
bool
)e.NewValue;
MessageBox.Show(checkedItem.Text +
" checked state is "
+ isChecked);
if
(isChecked)
{
this
.lastSelected = checkedItem;
}
}
I hope this helps. If you have any other questions or comments, please let me know.
All the best,
Peter
the Telerik team
Thanks for the snippet. It doesn't fit exactly what I expect, but I think I can get it using your sample.
Regards
Juergen
I am glad to hear that this solution works for you. Thank you for your feedback. We will consider implementing such event in one of our upcoming releases.
Do not hesitate to contact me if you have any other questions.
Sincerely yours,
Peter
the Telerik team