Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

ListBox Checkbox

Posted on 2006-04-04
9
Medium Priority
?
1,544 Views
Last Modified: 2008-02-26
In .Net 1.1 I used a listbox added checkboxes and use the following to check if something was checked:
 
if (LstFields.CheckedItems.Count > 0)

I tried using the same in  .Net 2.0 the .CheckedItems property does not exist.  Does anybody know the new syntax?

Thanks.

0
Comment
Question by:yanci1179
  • 5
  • 4
9 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 16374750
Are you using a standard ListBox or a CheckedListBox ?
0
 

Author Comment

by:yanci1179
ID: 16374824
in 1.1 I used a standart ListBox and then I just added the checkboxes.   There is a property called 'CheckBoxes' and I set it to true.  The property is not available in 2.0.  Was it removed?  I guess I can look at CheckedListBox
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 16374838
I assume that CheckedListbox is the replacement for a Listbox with the checkboxes option.

I tried a CheckedListBox in 2.0 and the CheckedItems member is there.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:yanci1179
ID: 16374975
thanks, I am just going to go ahead and use the CheckedListBox (I don't really have a choice).

In 1.1. I used

foreach (ListViewItem li in LstFields.CheckedItems)

Do you know what the equivalent of ListViewItem is for the CheckedListBox

0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 16375079
Well according to the documentation, CheckedListBox derives from ListBox so I would guess its the same as with the ListBox.
0
 

Author Comment

by:yanci1179
ID: 16375227
no, I'm getting an error when I use ListViewItem
0
 

Author Comment

by:yanci1179
ID: 16375277
In 1.1 I had a dynamic ListBox which would populate base on the users selection.  Then I used the text of the checkbox to create dynamic labels and textboxes:

I worked fine, but it does not work in 2.0


foreach (ListViewItem li in ChkLstFields.CheckedItems)
 {
       ct += 1;

       if (li.Text == "Method")
       {
          //create label based on the text
         //create combobox based on the text
        }
        else if (li.Text == "Neigh")
        {
            //create label based on the text
         //create combobox based on the text
         }
}
   
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 800 total points
ID: 16375304
This seems to work, its a little odd that it appears to have gone from ListViewItem to string, but there we go:

            foreach (string c in checkedListBox1.CheckedItems)
            {
                MessageBox.Show(c);
            }
0
 

Author Comment

by:yanci1179
ID: 16375480
It Worked!!!!  Thanks so much!!!!!!!!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Integration Management Part 2
Screencast - Getting to Know the Pipeline

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question