Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic ItemSelecting event (Read 5278 times)
springy
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 76
Joined: Jan 25th, 2010
ItemSelecting event
Feb 2nd, 2010 at 12:36pm
Print Post  
Hello,

when clicking inside empty space after an item previously has been selected then this event gets raised but e.Item is not null (as someone would expect) but contains the last selected item.

I simply wanted to limit the selection to one single item:
Code
Select All
e.Confirm = e.Item == null || this.calendar.ItemSelection.Count == 0; 



but now I can only optically deselect an item but the ItemSelectionComplete event does not get triggered because e.Confirm is false.
  

/\/\arkus.
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: ItemSelecting event
Reply #1 - Feb 2nd, 2010 at 4:29pm
Print Post  
The ItemSelecting event was bugged and was raised instead of ItemDeselecting when an item is being deselected. Here you can download yet another version of the control:

https://mindfusion.eu/_pln_trial/MindFusion.Scheduling.Wpf.2.1e.zip

The pair of events should now be raised as expected.

However, when you attempt to select an item when another item is selected, first the selected item gets deselected, then the second item gets selected. Therefore the ItemDeselecting event is raised first and you are not able to determine then whether the item is being deselected due to another item being selected or due to clicking on an empty cell. A possible way to implement your scenario in this case could be the following:

Declare a variable to store the last deselected item. If an item is selected, clear the variable. In the ItemSelectionComplete you can inspect the value of this variable and, if not null, restore the selection of the last deselected item. Not the most elegant approach but it works.

Code
Select All
private void c_ItemSelecting(object sender, ItemConfirmEventArgs e)
{
      if (c.ItemSelection.Items.Length > 0)
            e.Confirm = false;
      lastDeselectedItem = null;
}

private void c_ItemDeselecting(object sender, ItemConfirmEventArgs e)
{
      lastDeselectedItem = e.Item;
}

void c_ItemSelectionComplete(object sender, EventArgs e)
{
      if (lastDeselectedItem != null)
            c.ItemSelection.Add(lastDeselectedItem);
}

private Item lastDeselectedItem = null; 


There is an additional check in the ItemSelecting event, which prevents more than one item to be selected at the same time with the CTRL key. I am not sure if this is a requirement in your case.

Additionally, the ItemCloning event is fixed in the above version. It should now be raised before the item is actually cloned and will provide as argument the item being cloned, instead of the clone.

Regards,
Meppy
  
Back to top
 
IP Logged
 
springy
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 76
Joined: Jan 25th, 2010
Re: ItemSelecting event
Reply #2 - Feb 2nd, 2010 at 5:16pm
Print Post  
Quote:
which prevents more than one item to be selected at the same time with the CTRL key. I am not sure if this is a requirement in your case.


In fact this was the only requirement I wanted to enforce Wink

The events now occur well -- but the cloned item no longer is of my custom type: InplaceCreation still works correctly (respecting InteractiveItemType) and the old version already presented a cloned item of the correct derived type, but now it's only the built-in appointment class.
  

/\/\arkus.
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: ItemSelecting event
Reply #3 - Feb 3rd, 2010 at 7:02am
Print Post  
The cloned items are now created through the Item.Clone method as was initially intended. Try overriding this method in your custom class and instantiate an item of the appropriate type. Take a look at Tutorial 4 for some hints when creating custom item types.

Regards,
Meppy
  
Back to top
 
IP Logged
 
springy
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 76
Joined: Jan 25th, 2010
Re: ItemSelecting event
Reply #4 - Feb 3rd, 2010 at 9:15am
Print Post  
Aah, thanx.

Assuming the current Appointment.Clone() method looks this way:
Code
Select All
Appointment result = new Appointment();
result.PropX = this.PropX;
result.PropY = this.PropY;
[..]
return result;
 



it would be great if you could refactor this code into a new method like this:
Code
Select All
protected void CloneTo(Appointment target){
target.PropX = this.PropX;
[..]
}
 



and so the original Clone method would just look like this:
Code
Select All
Appointment result = new Appointment();
this.CloneTo(result);
return result;
 



This way I would not have to take care for properties introduced in the future by Mindfusion since I just would call Appointment.CloneTo() in my Clone method inside Appointment-derived classes.
  

/\/\arkus.
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: ItemSelecting event
Reply #5 - Feb 3rd, 2010 at 9:43am
Print Post  
This is a valid point and something we have previously considered implementing. I will see if we can add this for the next release.

Your feedback is most valuable.

Regards,
Meppy
  
Back to top
 
IP Logged
 
springy
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 76
Joined: Jan 25th, 2010
Re: ItemSelecting event
Reply #6 - Feb 3rd, 2010 at 10:13am
Print Post  
Little correction:

Ideally the class Item would get a method "void CloneTo(Item target)", too, which handles all properties which belong to the Item class.

Appointment.CloneTo would then call Item.CloneTo first (as Appointment derivants would call Appointment.CloneTo first).
  

/\/\arkus.
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint