Click here to Skip to main content
15,893,487 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hello everyone,

I am working on a project an I have a problem with using checked list boxes. I have 5 items which were inserted in a checked listboxes and I have put in an array all the items prices.(10,20,30,40,50) accordingly. I want this;

* When user clicked item1 the actual price will be 10 $
* When user clicked item2 the actual price will be 30 $(Both 1 and 2)
* When user Re-clicked item1 the actual price will be 20 $(Just second item clicked)

and so on.

C#
if (checkedListBoxAdditions.CheckedItems.Count != 0)
   {
   string s = "";
            for (int x = 0; x <= checkedListBoxAdditions.CheckedItems.Count - 1; x++)
     {
         if (checkedListBoxAdditions. == true)
         {
             totalAmount = totalAmount + price[4];
         }
         if (x == 2)
         {
             totalAmount = totalAmount + price[5];
         }
         if (x == 3)
         {
             totalAmount = totalAmount + price[6];
         }
         if (x == 4)
         {
             totalAmount = totalAmount + price[7];
         }
         if (x == 5)
         {
             totalAmount = totalAmount + price[8];
         }

     }
            MessageBox.Show(totalAmount + "");


   }

Here is the code that I tried. I really need help.
Thanks everyone.
Posted
Comments
[no name] 10-Oct-12 15:24pm    
Firstly, this code will not even compile.
Secondly, price[5] through price[8] are outside the bounds of the array as you have presented here.
Sergey Alexandrovich Kryukov 10-Oct-12 15:55pm    
Main thing is: this is the total UI abuse. Cannot be usable. Please see my answer.
Given the data model and use cases (logical, not UI), I'm sure I would be able to design it in intuitively readable way.
--SA
FoxRoot 10-Oct-12 15:48pm    
"Secondly, price[5] through price[8] are outside the bounds of the array as you have presented here."
Wes Aday x and price are different variables. I couldn't understand your sentence.
ıf this manner is wrong could you give me better structure please?
FoxRoot 10-Oct-12 15:51pm    
Wes Aday I can see now. That is not important so much. I have much more array elemnts. Think there are 10 is the 4th element of array(0,1,2,3,10,20,30,40,50)
Sergey Alexandrovich Kryukov 10-Oct-12 15:53pm    
On world to characterize this IU design idea: abuse.
--SA

1 solution

What you want will confuse the user. Don't do it. A check box, no matter in what container, is logically considered as a bit of data. More then one check boxes in the same list or a group box can be checked, and this is considered as logical OR of them; this way, the user can select any combination of checked states, such as "features". The visible state of the check boxed should unambiguously define the state of data; in other words, not "history of checks" should affect data. (In other cases, this is allowed; take the sorting data in columns of the grid view.)

If you don't observe these simple rules based on reasonable user's assumption stemmed from long history of common practice, consider your application as dead. People won't be able to use it the way you design.

—SA
 
Share this answer
 
Comments
FoxRoot 10-Oct-12 15:57pm    
Sergey thanks for your consideration. However, I couldnt understand. I am new at this topics.
Sergey Alexandrovich Kryukov 10-Oct-12 16:13pm    
Which topic? Programming? But this is forum on programming. After all, are you going to get experienced? I'll tell you what: if a novice comes too a gym for weightlifting, he is not supposed to say "I'm too week to lift this weight", but he starts lifting lighter weights and work hard, to be able to take that bigger weight later.

If you explain what you could not understand, I'll try to explain more clearly.
--SA
FoxRoot 10-Oct-12 16:24pm    
That was a good example :)
Sergey actually I am trying different methods. But some of them does not work some of them syntax error. I cant manage the code .Actually I don't know how to use checked list boxes and its properties.
Sergey Alexandrovich Kryukov 10-Oct-12 16:32pm    
You did not explain what exactly about syntax errors, etc. Let's focus on your problem. What exactly you don't know? And my advice is about design only. If you have N check boxes, the use can select any of then, and one look should be enough to see what's selected, not taking into account history of click the way you suggest. You need to keep is simple (K.I.S.S.). The check buttons should represent a selected subset of a finite set, and never anything else.
--SA
FoxRoot 10-Oct-12 16:50pm    
Actually I just want this. When a checkbox was checked I want to add something to something. and then İf this checkbox is re-checked(namely empty) I want to restore the past data.
I cant handle the logic(the if and else) and I dont know to check the boxes :(

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