Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

C# WinForms:

A Combobox with some items in in.
A spread sheet with some items in it. Each row also has a check-box so users can select them.

User picks an items in the combobox and clicks a Save button. It means associate that Combobox item to those selected items in the spreadsheet.

Q1: What's a good structure I can use to keep track of which combobox item is associated with which items from the spreadsheet?

NOTE: User can also Move up or Mode Down the items in the spreadsheet. So it gets a little tricky here, they might have associated some items, then they change the order or those items but we still need to know what items are selected for each combobox item

Q2: What's a good approach to keep track of that?

share|improve this question
2  
Please don't cross post - stackoverflow.com/questions/10639599/… –  ChrisF May 17 '12 at 16:26
    
Thanks Chris, It was because of the type of the question. It needed both an algorithm not necessarily specific to one language and it also had something to do with controls of one specific language. –  BDotA May 17 '12 at 16:32

2 Answers 2

up vote 1 down vote accepted

You can have a list of ComboBox item and each ComboBox item have a list of associated spreadsheet items.

public class AssociatedComboItem
{
    public ComboItemType ComboItem{get;set;}
    public List<SSItem> Items{get;set;} // SpreadSheet items
}

and then somewhere in your context, keep a list of AssociatedComboItem's to have all ComboBox items and their associated SpreadSheet items.

public List<AssociatedComboItem> Items{get;set;}
...
Items.Where(c=>c.ComboItem == someComboItem).FirstOrDefault(); // To get some comboItem reference

Items.Where(c=>c.Items.Contains(ss=>ss == someSpreadSheetItem)).FirstOrDefault(); // To find a ComboBox item which contains a specific SpreadSheet item
share|improve this answer

I think both questions can be answered at once. A Dictionary for sure. You can keep track of which item (key) is associated with item(s) (value(s)) on the spreadsheet. It's important to associate the key and its value(s) before order changes so the correct associations have been made. If you want spaghetti to be matched with meatballs and parmesean cheese, you don't want to sort in which sphagetti is matched with peanut butter.

NOTE: A tuple is two items paired together. A dictionary is a pair that associates a key with its value(s).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.