473,396 Members | 1,996 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

databinding to a dictionary

I have a custom dictionary and i would like to bind it to a control.
Since Dictionary doesn't implement IList i would have to write it. Is
the only way to do this to keep another collection that matches the key
in the dictionary to an index in the collection?

dan

Here is the code i want to add IList to.

public interface ISystemMessageData
{
String MessageID { get; set;}
String WhseID { get; set;}
String Flag { get; set;}
String MessageDate { get; set;}
String UserID { get; set;}
String Message { get; set;}
String PersonID { get; set;}
String MachineName { get; set;}
String DeviceID { get; set;}
String Subject { get; set;}
String ToEmail { get; set;}
String EmailFlag { get; set;}
String FromEmail { get; set;}
}
[Serializable]
public class RemoteDataCollection<TKey, TValue> :
System.Collections.Generic.Dictionary<TKey, TValue>
{
public RemoteDataCollection() { }
protected
RemoteDataCollection(System.Runtime.Serialization. SerializationInfo
info, System.Runtime.Serialization.StreamingContext context) :
base(info, context) { }
}

[Serializable]
public class SystemMessageDataCollection :
RemoteDataCollection<String, ISystemMessageData>
{
public SystemMessageDataCollection() { }
protected
SystemMessageDataCollection(System.Runtime.Seriali zation.SerializationInfo
info, System.Runtime.Serialization.StreamingContext context):base(info,
context){}
}
Mar 3 '06 #1
1 2450
Here is what i did and i must have done something wrong cause it doesn't
work. What did i do wrong?

[Serializable]
public class RemoteDataCollection<TKey, TValue> :
System.Collections.Generic.Dictionary<TKey, TValue>, IList<TValue>
{
protected System.Collections.Generic.List<TValue> _list = null;
public RemoteDataCollection()
{
_list = new List<TValue>();
}
protected
RemoteDataCollection(System.Runtime.Serialization. SerializationInfo
info, System.Runtime.Serialization.StreamingContext context) :
base(info, context) { }

public virtual void Add(TKey key, TValue value)
{
base.Add(key, value);
_list.Add(value);
}
public virtual bool Remove(TKey key)
{
TValue value;
bool b = this.TryGetValue(key, out value);
_list.Remove(value);
base.Remove(key);
return b;
}

#region IList<TValue> Members

public int IndexOf(TValue item)
{
return _list.IndexOf(item);
}

public void Insert(int index, TValue item)
{
throw new Exception("The method or operation is not
implemented: RemoveAt.");
}

public void RemoveAt(int index)
{
throw new Exception("The method or operation is not
implemented: RemoveAt.");
}

public TValue this[int index]
{
get
{
throw new Exception("The method or operation is not
implemented.");
}
set
{
throw new Exception("The method or operation is not
implemented.");
}
}

#endregion

#region ICollection<TValue> Members

public void Add(TValue item)
{

((System.Collections.Generic.ICollection<TValue>)b ase.Values).Add(item);
}

public bool Contains(TValue item)
{
return
((System.Collections.Generic.ICollection<TValue>)b ase.Values).Contains(item);
}

public void CopyTo(TValue[] array, int arrayIndex)
{

((System.Collections.Generic.ICollection<TValue>)b ase.Values).CopyTo(array,
arrayIndex);
}

public bool IsReadOnly
{
get { return
((System.Collections.Generic.ICollection<TValue>)b ase.Values).IsReadOnly; }
}

public bool Remove(TValue item)
{

((System.Collections.Generic.ICollection<TValue>)b ase.Values).Remove(item) ;
return true;
}

#endregion

#region IEnumerable<TValue> Members

public new IEnumerator<TValue> GetEnumerator()
{
return this.GetEnumerator();
}

#endregion
}

Dan Holmes wrote:
I have a custom dictionary and i would like to bind it to a control.
Since Dictionary doesn't implement IList i would have to write it. Is
the only way to do this to keep another collection that matches the key
in the dictionary to an index in the collection?

Mar 3 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: john wright | last post by:
I have a dictionary oject I created and I want to bind a listbox to it. I am including the code for the dictionary object. Here is the error I am getting: "System.Exception: Complex...
8
by: GaryDean | last post by:
We have been noticing that questions on vs.2005/2.0 don't appear to get much in answers so I'm reposting some questions posted by some of the programmers here in our organization that never got...
7
by: Pieter | last post by:
Hi, I'm looking for a DateTimePicker that supports 100% databinding (and support null-values)... It's a shame that the normal control doesn't, but when searching on the internet, I didn't find...
5
by: Ily | last post by:
Hi I have a collection of person objects that are added to a dictionary, each items is added with a unque key. Each person object has a first name property, and a last name property My...
8
by: Dirk | last post by:
Hello, I have a problem to use databinding with my business layer classes. My data class does not have simple properties (string, int or datetime), instead, all my properties are objects of the...
2
by: cjard | last post by:
I ask, because I have a textbox bound to a bindingsource, which is bound to a datatable(row) The datatable is typed, and hence exports a Property called Column1 I added another property to the...
0
by: Andy B | last post by:
Is there a way to databind a checkBoxList to a Dictionary<string, string> object? If so, how do you do it?
8
by: Andy B | last post by:
I have the object property StockContract.Dictionary which is a dictionary collection of <string, stringkey/value pairs. I need to be able to retreive the keys and their values and display them on a...
0
by: Andy B | last post by:
I have the following gridview. There are 2 other textBoxes and a button on the page as well. When somebody puts text into the 2 textBoxes and presses the add button, it puts the values of those...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.