makeNicePlusOne
makeNicePlusOne

Reputation: 33

Unlimited number of checkboxes

I wonder how to create mechanism which create new checkbox below previous when you click on button. Number of checkboxes are unlimited. I don't think that table of objects work well, so I think about implementation in list of objects. Any suggestions?

Upvotes: 0

Views: 227

Answers (2)

Ajay
Ajay

Reputation: 18421

What would you do with unlimited number of check boxes - confuse the user? So, that he/she wouldn't attempt to use it again? Bad idea, as you can guess now.

You may (should) limit the number of check boxes (or better, limit the number of controls on form/dialog). IMO, more than 10-12 CBs would be cumbersome for the end user. Therefore, better idea is to have all of them on dialog/dialog-resource, and make all of them invisible/disabled. When user does some action, make them visible/enabled - so that end user may do something with it.

Still demand N number of CBs, where N is not determined beforehand? Then you may have checkboxes under Combo box, or use check-boxes under List Control. List Control already hosts this feature, but for CBs under Combo, you may need to write your own class.See this article as an example.

Upvotes: 0

INS
INS

Reputation: 10820

Here is what I would do:

  1. Create an event for clicking that button (let's call it OnBtnClick)
  2. Use a vector/list to hold all the checkboxes
  3. When OnBtnClick is called you do:
    • create a checkbox with the desired position and size and make sure it receives an unique id (this will help you differentiate between checkboxes when they are clicked/checked/etc).
    • add the checkbox to the list (to get its status: checked or not checked)
    • add the checkbox to the desired window, the parent window (though this may happen automatically when you create it)
    • if you want to add an event for the added checkbox you should check the manual of your GUI framework (you will probably use the same event handler for all checkboxes and treat them separately based on their id)

Depending on the GUI framework used the bottom details may vary but the idea remains the same. I did this with wxWidgets, QT and MFC but I don't know which framework you use. You should be able to find code samples for each framework.

Upvotes: 1

Related Questions