in

C1 Community

ComponentOne Community is a free source for developers and help authors to collaborate and communicate.

Refresh Appointment Storage when binding C1Schedule to ObservableCollection<T>

Last post 07-05-2008 1:22 AM by duydoan. 8 replies.
Page 1 of 1 (9 items)
Sort Posts: Previous Next
  • 07-01-2008 1:38 AM

    Refresh Appointment Storage when binding C1Schedule to ObservableCollection<T>

    Hi, I'm binding AppointmentStorage to ObservableCollection<T> like this:
    private ObservableCollection<DM_SDLSchedule> listSource;
    then bind at loading time.
    C1ScheduleMain.DataStorage.AppointmentStorage.DataSource = listSource;
    C1ScheduleMain.DataStorage.AppointmentStorage.ResetBindings(
    false);

    How can i refresh UI of C1Schedule without re-bind when listsource changed (new, remove items).

  • 07-01-2008 6:44 AM In reply to

    Re: Refresh Appointment Storage when binding C1Schedule to ObservableCollection<T>

    > Hi, I'm binding AppointmentStorage to ObservableCollection like this:
    > privateObservableCollection listSource;
    > then bind at loading time.
    > C1ScheduleMain.DataStorage.AppointmentStorage.DataSource = listSource;
    > C1ScheduleMain.DataStorage.AppointmentStorage.ResetBindings(false);
    >
    > How can i refresh UI of C1Schedule without re-bind when listsource changed (new, remove
    > items).

    Well, there are some possible ways:

    1. imlement IBindingList interface in your custom class, inherited from
    ObservableCollection.

    2. call c1Sched.DataStorage.AppointmentStorage.RefreshData() after adding or removing
    items to your listSource:

    listSource.Add(new DM_SDLSchedule());
    c1Sched.DataStorage.AppointmentStorage.RefreshData();

    3. add or remove items with c1Sched.DataStorage.AppointmentStorage Add and Remove methods
    instead of corresponding methods of your listSource:

    c1Sched.DataStorage.AppointmentStorage.Add(new DM_SDLSchedule());
  • 07-02-2008 3:30 AM In reply to

    Re: Refresh Appointment Storage when binding C1Schedule to ObservableCollection<T>

    Thanks. Seemly IBindingList is my best choice. But it will be greate if C1Schedule DataStorage supports ICollectionChanged and IPropertyChanged. I did nothing when binding ObservableCollection<T> to other controls, they know these interfaces implicitly.

  • 07-02-2008 4:21 AM In reply to

    Re: Refresh Appointment Storage when binding C1Schedule to ObservableCollection<T>

    Again, i bound it to IBindingList, Add, Remove are OK, UI refresh data, but it doesn't work when edit an appointment. After i call IBindingList.ItemChanged(item), nothing happens. What i need to do for Edit case. Here is my IBindingList implementation:

    I also implemented INotifyPropertyChanged but helpless.

    using System;

    using System.ComponentModel;

    using System.Collections;

    using System.Collections.Generic;

    using System.Collections.ObjectModel;

    using System.Text;

    using UDx.G8H.AppSvc.DataModel;

    namespace UDx.G8H.SmartClients.Office

    {

    public class SDLScheduleBindingList: CollectionBase, IBindingList

    {

    private ListChangedEventArgs resetEvent = new ListChangedEventArgs(ListChangedType.Reset, -1);

    private ListChangedEventHandler onListChanged;

    public void LoadList(List<DM_SDLSchedule> ListSource)

    {

    IList l = (IList)this;foreach(DM_SDLSchedule _one in ListSource) l.Add(_one);

    OnListChanged(resetEvent);

    }

    public DM_SDLSchedule this[int index]

    {

    get { return (DM_SDLSchedule)(List[index]); }set { List[index] = value; }

    }

    public int Add (DM_SDLSchedule value)

    {

    return List.Add(value);

    }

    public DM_SDLSchedule AddNew()

    {

    return (DM_SDLSchedule)((IBindingList)this).AddNew();

    }

    public void Remove (DM_SDLSchedule value)

    {

    List.Remove(value);

    }

    protected virtual void OnListChanged(ListChangedEventArgs ev)

    {

    if (onListChanged != null) {onListChanged(this, ev);

    }

    }

    protected override void OnClear()

    {

    //

    }

    protected override void OnClearComplete()

    {

    OnListChanged(resetEvent);

    }

    protected override void OnInsertComplete(int index, object value)

    {

    DM_SDLSchedule c = (DM_SDLSchedule)value;OnListChanged(new ListChangedEventArgs(ListChangedType.ItemAdded, index));

    }

    protected override void OnRemoveComplete(int index, object value)

    {

    DM_SDLSchedule c = (DM_SDLSchedule)value;

    OnListChanged(new ListChangedEventArgs(ListChangedType.ItemDeleted, index));

    }

    protected override void OnSetComplete(int index, object oldValue, object newValue)

    {

    if (oldValue != newValue) {

    DM_SDLSchedule olditem = (DM_SDLSchedule)oldValue;

    DM_SDLSchedule newitem = (DM_SDLSchedule)newValue;OnListChanged(new ListChangedEventArgs(ListChangedType.ItemAdded, index));

    }

    }

    // Called by item when it changes.

    internal void ItemChanged(DM_SDLSchedule item)

    {

    int index = List.IndexOf(item);OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, index));

    }

    // Implements IBindingList.

    bool IBindingList.AllowEdit

    {

    get { return true ; }

    }

    bool IBindingList.AllowNew

    {

    get { return true ; }

    }

    bool IBindingList.AllowRemove

    {

    get { return true ; }

    }

    bool IBindingList.SupportsChangeNotification

    {

    get { return true ; }

    }

    bool IBindingList.SupportsSearching

    {

    get { return false ; }

    }

    bool IBindingList.SupportsSorting

    {

    get { return false ; }

    }

    // Events.

    public event ListChangedEventHandler ListChanged

    {

    add { onListChanged += value; }remove { onListChanged -= value; }

    }

    // Methods.

    object IBindingList.AddNew()

    {

    DM_SDLSchedule c = new DM_SDLSchedule();

    List.Add(c);

    return c;

    }

    // Unsupported properties.

    bool IBindingList.IsSorted

    {

    get { throw new NotSupportedException(); }

    }

    ListSortDirection IBindingList.SortDirection

    {

    get { throw new NotSupportedException(); }

    }

    PropertyDescriptor IBindingList.SortProperty

    {

    get { throw new NotSupportedException(); }

    }

     

    // Unsupported Methods.

    void IBindingList.AddIndex(PropertyDescriptor property)

    {

    throw new NotSupportedException();

    }

    void IBindingList.ApplySort(PropertyDescriptor property, ListSortDirection direction)

    {

    throw new NotSupportedException();

    }

    int IBindingList.Find(PropertyDescriptor property, object key)

    {

    throw new NotSupportedException();

    }

    void IBindingList.RemoveIndex(PropertyDescriptor property)

    {

    throw new NotSupportedException();

    }

    void IBindingList.RemoveSort()

    {

    throw new NotSupportedException();

    }

    }

     

    }

  • 07-02-2008 5:35 AM In reply to

    Re: Refresh Appointment Storage when binding C1Schedule to ObservableCollection<T>

    If your DM_SDLSchedule class implements INotifyPropertyChanged, all should work. Please,
    post here DM_SDLSchedule class definition, or send me your solution to
    IrinaP at componentone.com if possible. I'll take a look.

    --
    Thanks,
    --
    Irina
    ???????/???????? ? ???????? ?????????: news:206657@10.0.1.98...
    > Again, i bound it to IBindingList, Add, Remove are OK, UI refresh data, but it doesn't
    > work when edit an appointment. After i call IBindingList.ItemChanged(item), nothing
    > happens. What i need to do for Edit case. Here is my IBindingList implementation:
    >
    > I also implemented INotifyPropertyChanged but helpless.
    >
    > using System;
    >
    > using System.ComponentModel;
    >
    > using System.Collections;
    >
    > using System.Collections.Generic;
    >
    > using System.Collections.ObjectModel;
    >
    > using System.Text;
    >
    > using UDx.G8H.AppSvc.DataModel;namespace UDx.G8H.SmartClients.Office
    >
    > {
    >
    > publicclassSDLScheduleBindingList: CollectionBase, IBindingList
    >
    > {privateListChangedEventArgs resetEvent =
    > newListChangedEventArgs(ListChangedType.Reset, -1);
    >
    > privateListChangedEventHandler onListChanged;publicvoid LoadList(List
    > ListSource)
    >
    > {IList l = (IList)this;foreach(DM_SDLSchedule _one in ListSource) l.Add(_one);
    >
    > OnListChanged(resetEvent);
    >
    > }publicDM_SDLSchedulethis[int index]
    >
    > {get { return (DM_SDLSchedule)(List[index]); }set { List[index] = value; }
    >
    > }publicint Add (DM_SDLSchedule value)
    >
    > {return List.Add(value);
    >
    > }publicDM_SDLSchedule AddNew()
    >
    > {return (DM_SDLSchedule)((IBindingList)this).AddNew();
    >
    > }publicvoid Remove (DM_SDLSchedule value)
    >
    > {
    >
    > List.Remove(value);
    >
    > }protectedvirtualvoid OnListChanged(ListChangedEventArgs ev)
    >
    > {if (onListChanged != null) {onListChanged(this, ev);
    >
    > }
    >
    > }protectedoverridevoid OnClear()
    >
    > {
    >
    > //
    >
    > }protectedoverridevoid OnClearComplete()
    >
    > {
    >
    > OnListChanged(resetEvent);
    >
    > }protectedoverridevoid OnInsertComplete(int index, object value)
    >
    > {DM_SDLSchedule c =
    > (DM_SDLSchedule)value;OnListChanged(newListChangedEventArgs(ListChangedType.ItemAdded,
    > index));
    >
    > }protectedoverridevoid OnRemoveComplete(int index, object value)
    >
    > {
    >
    > DM_SDLSchedule c =
    > (DM_SDLSchedule)value;OnListChanged(newListChangedEventArgs(ListChangedType.ItemDeleted,
    > index));
    >
    > }protectedoverridevoid OnSetComplete(int index, object oldValue, object newValue)
    >
    > {if (oldValue != newValue) {
    >
    > DM_SDLSchedule olditem = (DM_SDLSchedule)oldValue;DM_SDLSchedule newitem =
    > (DM_SDLSchedule)newValue;OnListChanged(newListChangedEventArgs(ListChangedType.ItemAdded,
    > index));
    >
    > }
    >
    > }
    >
    > // Called by item when it changes.internalvoid ItemChanged(DM_SDLSchedule item)
    >
    > {int index =
    > List.IndexOf(item);OnListChanged(newListChangedEventArgs(ListChangedType.ItemChanged,
    > index));
    >
    > }
    >
    > // Implements IBindingList.boolIBindingList.AllowEdit
    >
    > { get { returntrue ; }
    >
    > }boolIBindingList.AllowNew
    >
    > { get { returntrue ; }
    >
    > }boolIBindingList.AllowRemove
    >
    > { get { returntrue ; }
    >
    > }boolIBindingList.SupportsChangeNotification
    >
    > { get { returntrue ; }
    >
    > }boolIBindingList.SupportsSearching
    >
    > { get { returnfalse ; }
    >
    > }boolIBindingList.SupportsSorting
    >
    > { get { returnfalse ; }
    >
    > }
    >
    > // Events.publiceventListChangedEventHandler ListChanged
    >
    > {add { onListChanged += value; }remove { onListChanged -= value; }
    >
    > }
    >
    > // Methods.objectIBindingList.AddNew()
    >
    > {DM_SDLSchedule c = newDM_SDLSchedule();
    >
    > List.Add(c);return c;
    >
    > }
    >
    > // Unsupported properties.boolIBindingList.IsSorted
    >
    > { get { thrownewNotSupportedException(); }
    >
    > }ListSortDirectionIBindingList.SortDirection
    >
    > { get { thrownewNotSupportedException(); }
    >
    > }PropertyDescriptorIBindingList.SortProperty
    >
    > { get { thrownewNotSupportedException(); }
    >
    > }
    >
    >
    >
    > // Unsupported Methods.voidIBindingList.AddIndex(PropertyDescriptor property)
    >
    > {thrownewNotSupportedException();
    >
    > }voidIBindingList.ApplySort(PropertyDescriptor property, ListSortDirection direction)
    >
    > {thrownewNotSupportedException();
    >
    > }intIBindingList.Find(PropertyDescriptor property, object key)
    >
    > {thrownewNotSupportedException();
    >
    > }voidIBindingList.RemoveIndex(PropertyDescriptor property)
    >
    > {thrownewNotSupportedException();
    >
    > }voidIBindingList.RemoveSort()
    >
    > {thrownewNotSupportedException();
    >
    > }
    >
    > }
    >
    >
    >
    > }
    >
  • 07-02-2008 5:47 AM In reply to

    Re: Refresh Appointment Storage when binding C1Schedule to ObservableCollection<T>

    > Thanks. Seemly IBindingList is my best choice. But it will be greate if C1Schedule
    > DataStorage supports ICollectionChanged and IPropertyChanged. I did nothing when binding
    > ObservableCollection to other controls, they know these interfaces implicitly.

    Your are right about INotifyCollectionChanged interface.
    INotifyPropertyChanged supported in the current version.
  • 07-02-2008 6:03 AM In reply to

    Re: Refresh Appointment Storage when binding C1Schedule to ObservableCollection<T>

    Thanks you for lots of help. here is DM_SDLSchedule definition, I'm using WCF to serialize data to Client where C1Schedule using.

    using System;

    using System.ComponentModel;

    using System.Collections;

    using System.Runtime.Serialization;

    namespace UDx.G8H.AppSvc.DataModel

    {

    [
    DataContract(Namespace = "urn:UDx.G8H.SDL", Name = "SDLSchedule")]

    public sealed class DM_SDLSchedule: INotifyPropertyChanged

    {

    private Guid scheduleUID;private SDLScheduleType scheduleType;

     

    private string ownerUID;

    private string ownerCNName;

     

    private string subject;private string content;

     

    private DateTime startDate;

    private DateTime endDate;

     

    private string location;private string properties;

     

    private string attendeeUID;

    private string attendeeCNName;

     

    private string attendeesUIDList;private string attendeesCNNameList;

     

    private string attachUIDList;

    private string attachFileNameList;

     

    private SDLAttendingStatus attendingStatus;

     

    private bool sentYN;

     

    private string sourceScheduleUID;

     

    public DM_SDLSchedule()

    {

    ScheduleType =
    SDLScheduleType.Meeting;

    AttendingStatus = SDLAttendingStatus.None;

    sentYN = false;

    }

     

    public event PropertyChangedEventHandler PropertyChanged;protected void OnPropertyChanged(string name)

    {

    PropertyChangedEventHandler handler = PropertyChanged;

    if (handler != null)

    {

    handler(
    this, new PropertyChangedEventArgs(name));

    }

    }

     

    [
    DataMember]public Guid ScheduleUID

    {

    get { return scheduleUID; }

    set { this.scheduleUID = value; }

    }

     

    [
    DataMember]public SDLScheduleType ScheduleType

    {

    get { return scheduleType; }

    set { this.scheduleType = value; }

    }

     

    [
    DataMember]public string OwnerUID

    {

    get { return ownerUID; }

    set { this.ownerUID = value; }

    }

     

    [
    DataMember]public string OwnerCNName

    {

    get { return ownerCNName; }

    set { this.ownerCNName = value; }

    }

     

    [
    DataMember]public string Subject

    {

    get { return subject; }

    set { this.subject = value; OnPropertyChanged("Subject"); }

    }

     

    [
    DataMember]public string Content

    {

    get { return content; }

    set { this.content = value; }

    }

     

    [
    DataMember]public DateTime StartDate

    {

    get { return startDate; }

    set { this.startDate = value; OnPropertyChanged("StartDate"); }

    }

     

    [
    DataMember]public DateTime EndDate

    {

    get { return endDate; }

    set { this.endDate = value; OnPropertyChanged("EndDate"); }

    }

     

    [
    DataMember]public string Location

    {

    get { return location; }

    set { this.location = value; OnPropertyChanged("Location"); }

    }

     

    [
    DataMember]public string Properties

    {

    get { return properties; }

    set { this.properties = value; OnPropertyChanged("Properties"); }

    }

     

    [
    DataMember]public string AttendeeUID

    {

    get { return attendeeUID; }

    set { this.attendeeUID = value; }

    }

    [
    DataMember]public string AttendeeCNName

    {

    get { return attendeeCNName; }

    set { this.attendeeCNName = value; }

    }

     

    [
    DataMember]public string AttendeesUIDList

    {

    get { return attendeesUIDList; }

    set { this.attendeesUIDList = value; }

    }

    [
    DataMember]public string AttendeesCNNameList

    {

    get { return attendeesCNNameList; }

    set { this.attendeesCNNameList = value; }

    }

    [
    DataMember]public string AttachUIDList

    {

    get { return attachUIDList; }

    set { this.attachUIDList = value; }

    }

    [
    DataMember]public string AttachFileNameList

    {

    get { return attachFileNameList; }

    set { this.attachFileNameList = value; }

    }

    [
    DataMember]public SDLAttendingStatus AttendingStatus

    {

    get { return attendingStatus; }

    set { this.attendingStatus = value; }

    }

     

    [
    DataMember]public bool SentYN

    {

    get { return sentYN; }

    set { this.sentYN = value; }

    }

     

    [
    DataMember]public string SourceScheduleUID

    {

    get { return sourceScheduleUID; }

    set { this.sourceScheduleUID = value; }

    }

     

    ////////////////////

    public DM_SDLSchedule Clone()

    {

    DM_SDLSchedule _ret = new DM_SDLSchedule();

    _ret.ScheduleUID = System.Guid.NewGuid();

    _ret.ScheduleType = this.scheduleType;

     

    _ret.OwnerUID =
    this.ownerUID;_ret.OwnerCNName = this.ownerCNName;

     

    _ret.Subject = this.subject;

    _ret.Content = this.content;

     

    _ret.StartDate =
    this.startDate;_ret.EndDate = this.endDate;

     

    _ret.Location = this.location;

    _ret.Properties = this.properties;

     

    _ret.AttendeeUID =
    this.attendeeUID;_ret.AttendeeCNName = this.attendeeCNName;

     

    _ret.AttendeesUIDList = this.attendeesUIDList;

    _ret.AttendeesCNNameList = this.attendeesCNNameList;

     

    _ret.AttachUIDList =
    this.attachUIDList;_ret.AttachFileNameList = this.attachFileNameList;

     

    _ret.AttendingStatus = SDLAttendingStatus.None;

    _ret.SentYN = false;

     

    _ret.SourceScheduleUID =
    this.scheduleUID.ToString();

     

    return _ret;

    }

     

    }

     

    }

  • 07-04-2008 8:50 AM In reply to

    Re: Refresh Appointment Storage when binding C1Schedule to ObservableCollection<T>

    it seems, that it's our bug. The fix is under testing now and should be available on
    prerelease site soon.
    If you wnat to check whether it works for you, let me know your e-mail, I'll send it to
    you right now.
  • 07-05-2008 1:22 AM In reply to

    Re: Refresh Appointment Storage when binding C1Schedule to ObservableCollection<T>

    Appreciated for this. My office email is: duy at mk-solution dot com, also please cc to duydoan2004 at yahoo dot com.

Page 1 of 1 (9 items)
Contact ComponentOne: 1.800.858.2739 ©1987-2008 ComponentOne LLC All Rights Reserved.