Question

I am creating an add in for Microsoft Excel. In this program, I allow the user to make a deposit into a user-created budget. Accounts are divided by individual worksheets (one worksheet is an account for clothes, another account for auto work, etc.). Deposits are made using a form that lists all the accounts into a checked list box. The idea is to allow the user to automatically put a fraction of the deposit only into each account on the list that is checked. Any cash that isn't distributed is placed back into the main budget as idle cash.

The code I'm using at the moment is as follows:

decimal deposit = 0;
private void btnDeposit_Click(object sender, EventArgs e)
{
    deposit = Convert.ToDecimal(txtDeposit.Text);
    AccountingAddIn.ThisAddIn.blake.addToBudget(deposit);

    foreach (Account acc in AccountingAddIn.ThisAddIn.Accounts)
    {
        acc.addToBalance(deposit / AccountingAddIn.ThisAddIn.Accounts.Count);
        AccountingAddIn.ThisAddIn.blake.updateBudget(acc);
    }
}

The code itself works just fine. I can even select a list item and move it up and down the list with no errors. What I need to know is how do I specify the above function such that it only works on list items that are actually checked. More specifically, how do I determine if an item(s) in a checked list box is checked? If possible, please cite an example. Thanks!

Was it helpful?

Solution

What about the CheckedItems property found within the CheckedListBox component? From your code, I'm not sure how you go about adding each Account object to a CheckedListBox so to answer the second part of your question, here is a simple example of how to use the CheckedItems property for a generic CheckedListBox:

    foreach (var item in myCheckedListBox.CheckedItems)
        {
            //Perform some logic for each item which is checked.
        }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top