Click here to Skip to main content
16,022,413 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
Dear all,

I have a form in which there are many comboboxes, I have like for each different set of permutations of their values a "decision" is to be made. I tried to use a decision tree but couldn't implement it. How can I do this decision making process without many "if else", it would be crazy.

Regards,
Posted
Comments
Sergey Alexandrovich Kryukov 27-Apr-12 23:23pm    
Reason for my vote of 5
Pretty good idea, my 5.
--SA

It might help you,

Strategy method or Switch statement in C#[^]

Hope it helps :)
 
Share this answer
 
Yes, decision tree won't help you much. You should not use well-known structures all the time, sometimes you need to use your own brain. :-)

This is not permutations at all, but I can get the idea. This is just the combination of all different options.

You should create an options space. The dimension of the space should be a number of control. Let's assume, perhaps with some simplification, that all options are represented by check boxes, groups of radio boxes, and list or combo boxistes. Each group of radio boxes, each individual list or combo box and each individual check box will represent a special dimensions. Count them all (a radio box group counts as one) to get the total dimension of the space. In each dimension, you have final number of points: two for each check box, and several points depending on the number of choice items in each of the other cases. Let's say, you have N-dimensional space.

OK, now represent it simply as an array of the rank N and appropriate number of points (options) in each direction
ArrayType [,,,,] where number of commas is equal to N−1. Total number of option combinations will be a product of numbers of options in each dimensions.

Now, the question is: the array of what? What would be the type ArrayType? My answer is: it will be an array of delegate instances. You can create several method with the same signature (depending on application, but one parameter should be a multi-dimensional point, that is, a position in your multi-dimensional array). You can create several methods; you will create delegate instances and put identical instances in some array elements, different instances in others, depending on how options work. The point (multi-dimensional index) will describe all options at once.

Please see my somewhat similar idea in my CodeProject article:
Dynamic Method Dispatcher[^].

For another related construct, please see my design of a finite-state machine in another article, pay attention for the referenced chapter (3.6 Cartesian Square):
Enumeration Types do not Enumerate! Working around .NET and Language Limitations[^].

—SA
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900