473,498 Members | 1,936 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dicitionary Geneic Class

18 New Member
Hi All,
Can anyone help me out regarding Dicitonary Generic Class using c#.

Like I have 3 btns(add, edit and delete), text box , LisBox, Listview. If i add an item from Text it should be added to lIstbox and i have items in listview. They should be assigned to listbox selected item. these can be done through dicitonary classes. If i add new one Listbox item and new listview items are to be added to that selected item.
Jan 24 '09 #1
4 1406
mldisibio
190 Recognized Expert New Member
The ListBox displays a ListBox.ObjectCollection, which is simply a collection of objects.
The ListView contains a ListViewItemCollection which is a collection of ListViewItems.
A Dictionary has a collection of KeyValuePairs.

If you want the ListBox to somehow reflect the combination of the TextBox value and the ListView item, you might consider making the each ListBox item a KeyValuePair<string, ListViewItem>.
Jan 25 '09 #2
uday1302
18 New Member
I have Listbox(lstgroups) and listview(lstItems). say items in lisbox as Groups and in listview as Items.
Each Group should have list of items, when i add an new item to lstitems. it should assign to selected group.
By using dictionary classes
Here List<object> should return lstitems


Dictionary<string, List<object>> d= new Dictionary(string, List<object>>();

d.add(lstgroups.items, new List<object>);

//error cumes here, how to assign here List<>
Jan 27 '09 #3
vekipeki
229 Recognized Expert New Member
Here is an example of using Dictionary<>: System.Collections.Generic.Dictionary.

Try to explain what is the goal you are trying to accomplish, maybe you don't need a dictionary?

If you want to assing a list of items to a "group", the easiest way would be to create that list first, and then add it to the dictionary:

Expand|Select|Wrap|Line Numbers
  1. // create a list
  2. List<Object> someItems = new List<Object>;
  3.  
  4. // add some items
  5. someItems.AddRange( /* add the items */);
  6.  
  7. // add these items with a specified key ("group name")
  8. d.Add(groupName, someItems);
  9.  
Note also:
1. you have to do this for each group
2. you cannot add the same groupName twice (it will raise an exception)
Jan 27 '09 #4
mldisibio
190 Recognized Expert New Member
Small syntax note:
Expand|Select|Wrap|Line Numbers
  1. List<Object> someItems = new List<Object>();
Jan 27 '09 #5

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

Similar topics

1
10937
by: Murat Tasan | last post by:
hi, i am having a small problem with constructing an inner class. i am using an inner class (and not a static nested class) because the methods of the inner class need access to the enclosing...
2
9576
by: Fernando Rodriguez | last post by:
Hi, I need to traverse the methods defined in a class and its superclasses. This is the code I'm using: # An instance of class B should be able to check all the methods defined in B #and A,...
2
2019
by: Gabriel Genellina | last post by:
Hi In the following code sample, I have: - a Worker class, which could have a lot of methods and attributes. In particular, it has a 'bar' attribute. This class can be modified as needed. - a...
3
3027
by: Robert | last post by:
Python doesn't know the class of a method when container not direct class attribute: >>> class X: .... def f():pass .... g=f .... l= .... >>> X.g <unbound method X.f>
6
3175
by: Brian Jones | last post by:
I'm sure the solution may be obvious, but this problem is driving me mad. The following is my code: class a(object): mastervar = def __init__(self): print 'called a'
18
6928
by: John M. Gabriele | last post by:
I've done some C++ and Java in the past, and have recently learned a fair amount of Python. One thing I still really don't get though is the difference between class methods and instance methods. I...
4
3044
by: Edvard Majakari | last post by:
Hi, I just found py.test and converted a large unit test module to py.test format (which is actually almost-no-format-at-all, but I won't get there now). Having 348 test cases in the module and...
1
3317
by: Oplec | last post by:
Hi, I'm learning C++ as a hobby using The C++ Programming Language : Special Edition by Bjarne Stroustrup. I'm working on chpater 13 exercises that deal with templates. Exercise 13.9 asks for me...
13
2348
by: Bryan Parkoff | last post by:
I have created three classes according to my own design. First class is called CMain. It is the Top Class. Second class and third class are called CMemory and CMPU. They are the sub-classes....
0
7125
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
7203
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...
1
6885
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
7379
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
3093
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...
0
3081
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1417
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 ...
1
656
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
290
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...

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.