473,396 Members | 1,760 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

C# and listboxes

2
Hi
I'm trying to loop through the items in a listbox (files in a directory).
I've tried using the code/suggestions from another discusion

http://www.thescripts.com/forum/thread224496.html

"ListBox items accept objects of any type as elements. Find where the
elements are being added, and use that class in the foreach. For instance,
if you do this

listBox1.Items.Add(new MyCustomClass("Hi", 3, true));

then you would do this to get the values

foreach (MyCustomClass item in listBox1.Items) {
} "
,but keep on getting the following error.

"Error 1 foreach statement cannot operate on variables of type 'System.Windows.Forms.CheckedListBox' because 'System.Windows.Forms.CheckedListBox' does not contain a public definition for 'GetEnumerator' C:\Users\gerts\Documents\Visual Studio 2005\Projects\DirTest2\DirTest2\Form1.cs 341 13 DirTest2
"
any suggestions?

Thanks
Gert
Aug 24 '07 #1
2 1689
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4.  
  5. namespace WinApp1
  6. {
  7.     class myClass
  8.     {
  9.         private int dataInt;
  10.         private string dataStr;
  11.         private bool dataBool;
  12.  
  13.         public myClass(int dataInt, string dataStr, bool dataBool)
  14.         {
  15.             this.dataBool = dataBool;
  16.             this.dataInt = dataInt;
  17.             this.dataStr = dataStr;
  18.         }
  19.     }
  20. }
Expand|Select|Wrap|Line Numbers
  1.  private void button3_Click(object sender, EventArgs e)
  2.         {
  3.             for (int x = 0; x <= 10; x++)
  4.                 listBox1.Items.Add(new myClass(x,x.ToString(),true));
  5.         }
  6.  
  7.         private void button4_Click(object sender, EventArgs e)
  8.         {
  9.             foreach (myClass xx in listBox1.Items)
  10.                 MessageBox.Show(xx.ToString());
  11.         }
Hi
I'm trying to loop through the items in a listbox (files in a directory).
I've tried using the code/suggestions from another discusion

http://www.thescripts.com/forum/thread224496.html



,but keep on getting the following error.



any suggestions?

Thanks
Gert
Aug 24 '07 #2
GertS
2
Thanks a lot. That sorted my problem out 100%

Gert
Aug 24 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Jeffrey Barish | last post by:
I have an application that produces two listboxes. I would like to be able to select one of the items in the first listbox and one of the items in the second listbox. However, when I make my...
3
by: softengine | last post by:
Can and how do you alter a data view to include a look up field from another data table? The data table of the dataview only has the key, the value I need is in another data table. Can and how...
3
by: Simon Templar | last post by:
I need the following functionality: With 2 listboxes populated from a database with the SAME data, I need any of the listboxes to stop displaying the option when selected at the other listbox. Eg:...
9
by: Susan Bricker | last post by:
Hi. I have two questions ... (1) I want to use a Listbox to enable the user to select 1 or many items from the list. However, I'm having trouble figuring out how to find out t which items have...
4
by: bill yeager | last post by:
I have several template columns inside of a datagrid. Inside of these template columns are databound listboxes: <asp:TemplateColumn HeaderText="Crew Chiefs"> <ItemTemplate> <asp:listbox...
0
by: Terry D | last post by:
I'm having an issue with an ASP.NET page (VS.NET 2003, VB.NET, Oracle back end). The page uses the standard VS.NET grid to display the records from a particular table. The user can edit certain...
1
by: Ryan Ternier | last post by:
I have two listboxes, and allow users to move items between them via the following function: function SwitchList(fbox, tbox){ var arrFbox = new Array(); var arrTbox = new Array(); var...
0
by: Luis Esteban Valencia | last post by:
have a problem and I'm not sure how to handle/fix it. I have three listboxes on my page. The first listbox has a list of software products. When you select an item in the Products listbox, then...
2
by: salad | last post by:
This is a tip on how to speed up listboxes DRAMATICALLY. Persons that would benefit are those that are constantly updating the rowsource of a listbox/combobox in order to filter and sort the data...
0
by: amidala | last post by:
Hello, everyone, i've recently started using C# and i'm rather new to this language. I'm trying to make a small project now that is combining the basic knowledge of programming (according to me :) )....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.