Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Selecting Items Programatically (Read 4451 times)
danielbr
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 10
Joined: Mar 21st, 2006
Selecting Items Programatically
Oct 22nd, 2006 at 9:27pm
Print Post  
Hi.

Please can you tell me the best way to programatically select an item in the CalendarView control.

I have the CurrentView set to Timetable, and I have a number of items added to the Schedule associate with this View.

Essentially I want to be able to select the item, so that it moves into view in the Calendar and changes to the selected style, as if the user clicked the item. There is no inplace editing.

Thanks,

Daniel
  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: Selecting Items Programatically
Reply #1 - Oct 23rd, 2006 at 5:39am
Print Post  
To select items programatically, add them to the Calendar.ItemSelection collection. To deselect items, remove them from the collection. The following code selects the item referenced by the variable 'item'.

Code
Select All
calendar.ItemSelection.Add(item); 



Meppy
  
Back to top
 
IP Logged
 
danielbr
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 10
Joined: Mar 21st, 2006
Re: Selecting Items Programatically
Reply #2 - Oct 23rd, 2006 at 8:02am
Print Post  
Great, Thanks Meppy.

That certainly lets me select the item. However the view isn't scrolling when an item gets selected (I've got EnsureVisibleSelection set to true.)

I can get the day to show using the Selection.Set property; but do I have to write code to move the VScrollPos to scroll the selected item into view (I've included the code I'm using at the end of this post) or is there a better way?

Also FYI the help says that the ItemSelection Property is read only!

"public ItemSelection ItemSelection { get; }"

Regards,

Daniel


My Code:

Code
Select All
    Private Sub ScheduleSingletonPropertyChangedHandler(ByVal sender As Object, ByVal e As System.ComponentModel.PropertyChangedEventArgs)
        If e.PropertyName = "SelectedLesson" Then
            'The user's changed the selected lesson

            UXCalendar_Month.ItemSelection.Clear()
            UXCalendarDetailView.ItemSelection.Clear()

            If ScheduleSingleton.Instance.SelectedLesson IsNot Nothing Then
                UXCalendar_Month.Selection.Set(ScheduleSingleton.Instance.SelectedLesson.StartDate)
                UXCalendarDetailView.Selection.Set(ScheduleSingleton.Instance.SelectedLesson.StartDate)

                UXCalendar_Month.ItemSelection.Add(ScheduleSingleton.Instance.SelectedLesson.Appointment)
                UXCalendarDetailView.ItemSelection.Add(ScheduleSingleton.Instance.SelectedLesson.Appointment)
            End If
        End If
    End Sub 









  
Back to top
 
IP Logged
 
danielbr
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 10
Joined: Mar 21st, 2006
Re: Selecting Items Programatically
Reply #3 - Oct 23rd, 2006 at 8:13am
Print Post  
Doh, Of course the ItemSelection is read only. I'm sorry.

I can change the members of the itemselection, but can't replace the itemselection collection itself.

My apologies your help is correct! Opps.
  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: Selecting Items Programatically
Reply #4 - Oct 23rd, 2006 at 8:30am
Print Post  
There is much easier way to accomplish this, by calling the Calendar.EnsureVisible method and passing the item of interest as argument. The following code selects an item and brings it into view:

Code
Select All
Calendar.ItemSelection.Add(item)
Calendar.EnsureVisible(item) 



Meppy
  
Back to top
 
IP Logged
 
danielbr
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 10
Joined: Mar 21st, 2006
Re: Selecting Items Programatically
Reply #5 - Oct 23rd, 2006 at 9:45am
Print Post  
Brilliant. Thank you.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint