473,796 Members | 2,708 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 ISystemMessageD ata
{
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 RemoteDataColle ction<TKey, TValue> :
System.Collecti ons.Generic.Dic tionary<TKey, TValue>
{
public RemoteDataColle ction() { }
protected
RemoteDataColle ction(System.Ru ntime.Serializa tion.Serializat ionInfo
info, System.Runtime. Serialization.S treamingContext context) :
base(info, context) { }
}

[Serializable]
public class SystemMessageDa taCollection :
RemoteDataColle ction<String, ISystemMessageD ata>
{
public SystemMessageDa taCollection() { }
protected
SystemMessageDa taCollection(Sy stem.Runtime.Se rialization.Ser ializationInfo
info, System.Runtime. Serialization.S treamingContext context):base(i nfo,
context){}
}
Mar 3 '06 #1
1 2468
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 RemoteDataColle ction<TKey, TValue> :
System.Collecti ons.Generic.Dic tionary<TKey, TValue>, IList<TValue>
{
protected System.Collecti ons.Generic.Lis t<TValue> _list = null;
public RemoteDataColle ction()
{
_list = new List<TValue>();
}
protected
RemoteDataColle ction(System.Ru ntime.Serializa tion.Serializat ionInfo
info, System.Runtime. Serialization.S treamingContext 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.TryGetValu e(key, out value);
_list.Remove(va lue);
base.Remove(key );
return b;
}

#region IList<TValue> Members

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

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<TVa lue> Members

public void Add(TValue item)
{

((System.Collec tions.Generic.I Collection<TVal ue>)base.Values ).Add(item);
}

public bool Contains(TValue item)
{
return
((System.Collec tions.Generic.I Collection<TVal ue>)base.Values ).Contains(item );
}

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

((System.Collec tions.Generic.I Collection<TVal ue>)base.Values ).CopyTo(array,
arrayIndex);
}

public bool IsReadOnly
{
get { return
((System.Collec tions.Generic.I Collection<TVal ue>)base.Values ).IsReadOnly; }
}

public bool Remove(TValue item)
{

((System.Collec tions.Generic.I Collection<TVal ue>)base.Values ).Remove(item) ;
return true;
}

#endregion

#region IEnumerable<TVa lue> Members

public new IEnumerator<TVa lue> GetEnumerator()
{
return this.GetEnumera tor();
}

#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
9263
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 DataBinding accepts as a data source either an IList or an IListSource at System.Windows.Forms.ListControl.set_DataSource(Object value)
8
2186
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 answered... In 1.1 we always did our own myDataAdapter.fills and we liked that control for lots of good reasons. Now the new DataSource (or is it a TableAdapter:Dataset) automatically fills the Gridview. How can we control that fill? In a...
7
2586
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 any solution that works without problems. Does anybody know where I can find an inherited DateTimePicker that supports databinding and nulll-values? Any links, sample code etc would be really appreciated! It can be for VB.NET 2005, in case that...
5
4610
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 problem is I want to bind this to a dropdown list so that the DataValueField is set to the ID of the Person, and that the DataTextField displays the firstname of the person. The problem is I can only set the DataValueField to either "Key" or "Value",...
8
2091
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 generic type Field<T> (see sample code). public class Employee { public Field<stringForename
2
3267
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 datatable by editing the partial class, and Called it ColumnX - it simply returns "Hello World" all the time Then I tried to bind my textbox to it, editing the binding for .Text from xyzBindingSource - Column1
0
1347
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
1999
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 page. I want to use something like a repeater or something like that. I don't know if this would be code I will have to manually write myself, or if it can be done with dataBinding of some sort. I am using vs2008 and c# 3.5. Any ideas on how to...
0
2381
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 textBoxes into the DataTable. The gridView shows what values have already been entered into the DataTable. <asp:GridView ID="DefinitionList" runat="server" Caption="Dictionary entries" EmptyDataText="There are no definitions yet." AllowPaging="True"...
0
10461
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10190
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9057
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7555
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5447
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5579
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4122
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2928
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.