This is a migrated thread and some comments may be shown as answers.

[Solved] DataKeyField problem

4 Answers 167 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Radoslaw
Top achievements
Rank 1
Radoslaw asked on 12 Jan 2008, 04:37 PM
Hei!

assigning DataKeyField of scheduler the simple type works fine but since my DataKeyField keeps Dictionary<string,object> or public class i cant edit the appointments (It stays in the day/week/month view).
Can you tell me what is wrong and if i can use such objects inside DataKeyField?

regards
Radek

4 Answers, 1 is accepted

Sort by
0
T. Tsonev
Telerik team
answered on 14 Jan 2008, 04:28 PM
Hello Radoslaw,

The problem is that Dictionary<TKey, TValue> does not implement Equals. This makes finding the appointments by primary key impossible. You need to derive your own class from it and implement Equals, GetHashCode and make it serializable. Here is the implementation that I have came up with:

[Serializable] 
public class KeyDictionary : Dictionary<string, object>, IEquatable<KeyDictionary> 
{ 
    public KeyDictionary() 
        : base() 
    { 
    } 
 
    protected KeyDictionary(SerializationInfo info, StreamingContext context) 
        : base(info, context) 
    { 
    } 
 
    public override bool Equals(object obj) 
    { 
        KeyDictionary other = obj as KeyDictionary; 
        if (other == null) 
        { 
            return false; 
        } 
 
        return Equals(other); 
    } 
 
    public override int GetHashCode() 
    { 
        int hash = 0; 
 
        foreach (string key in this.Keys) 
        { 
            hash ^= key.GetHashCode(); 
        } 
 
        return hash; 
    } 
 
    public bool Equals(KeyDictionary other) 
    { 
        if (other == null) 
        { 
            return false; 
        } 
 
        if (other.Keys.Count != Keys.Count) 
        { 
            return false; 
        } 
 
        foreach (string key in other.Keys) 
        { 
            if (!other.ContainsKey(key)) 
            { 
                return false; 
            } 
 
            if (!other[key].Equals(this[key])) 
            { 
                return false; 
            } 
        } 
 
        return true; 
    } 
} 
 


Kind regards,
Tsvetomir Tsonev
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Radoslaw
Top achievements
Rank 1
answered on 17 Jan 2008, 08:08 AM
Thank You very much!!!

What about if i want to have as id string value (like MID:<some numbers>\r\n'Subject:<some text>\r\n). The strings are sometimes identical.
When i click on one appointment i sometimes get the another opened. Is it beacuse the strings are the same?

Radek
0
Radoslaw
Top achievements
Rank 1
answered on 17 Jan 2008, 08:24 AM
It seems to me that event if the strings are different scheduler has problems to open the clicked one...

0
T. Tsonev
Telerik team
answered on 17 Jan 2008, 04:10 PM
Hello Radoslaw,

The IDs should definitely be unique, otherwise RadScheduler will not work properly.
Can you please send us an example page that demonstrates the problem with RadScheduler opening the wrong appointment?

All the best,
Tsvetomir Tsonev
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Scheduler
Asked by
Radoslaw
Top achievements
Rank 1
Answers by
T. Tsonev
Telerik team
Radoslaw
Top achievements
Rank 1
Share this question
or