468,103 Members | 1,387 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,103 developers. It's quick & easy.

assign system.components.binding list<T> to a hash table

zybernau
hi everyone,
i need to know is that possible to assign binding list<> to a hashtable.?

if u guys know pls share..
here is the scenario,

i am having a bindinglist which is binded to a grid.
wat i need to do is check for duplicates in that grid, so i using bindinglist, n using foreach loop and able to find out.

so now, i need to accomplish the same thing with out foreach loop, for this i need hashtable opr some other collection


Thanks,
raj
Oct 1 '08 #1
2 1576
mldisibio
190 Expert 100+
No, you cannot "simply" assign a BindingList to a SortedDictionary or Hashtable. A BindingList implements IList<T> and the SortedDictionary implements IDictionary<TKey, TValue>
You could write a method, but at some point you would have to loop through your BindingList anyways in order to add each element, as well as figure out some key and value.

The simplest way to eliminate duplicates is to check if the item already exists before you add it to your BindingList, or before you update your BindingList from your Grid:

Expand|Select|Wrap|Line Numbers
  1. if(!myBindingList.Contains(itemToAdd))
  2.  myBindingList.Add(itemToAdd);
  3. else
  4.  throw new ArgumentException("Duplicate List Item")
  5.  
Oct 1 '08 #2
No, you cannot "simply" assign a BindingList to a SortedDictionary or Hashtable. A BindingList implements IList<T> and the SortedDictionary implements IDictionary<TKey, TValue>
You could write a method, but at some point you would have to loop through your BindingList anyways in order to add each element, as well as figure out some key and value.

The simplest way to eliminate duplicates is to check if the item already exists before you add it to your BindingList, or before you update your BindingList from your Grid:

Expand|Select|Wrap|Line Numbers
  1. if(!myBindingList.Contains(itemToAdd))
  2.  myBindingList.Add(itemToAdd);
  3. else
  4.  throw new ArgumentException("Duplicate List Item")
  5.  
thank you buddy.. your suggestion is very helpful
Oct 6 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

14 posts views Thread by Dave | last post: by
3 posts views Thread by Eric | last post: by
2 posts views Thread by Brian Pelton | last post: by
5 posts views Thread by PJ | last post: by
4 posts views Thread by =?Utf-8?B?TGFycnlS?= | last post: by
7 posts views Thread by Andrew Robinson | last post: by
44 posts views Thread by Zytan | last post: by
1 post views Thread by Solo | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.