Member Avatar for Erwin_Rosyid

I stuck against the wall again in implementing list of classes.

In the nutshell:

The idea is to put a LIST containing several CLASS, the Class content can only be manipulated and accessed with get and set method (which is already established). To add a value inside Job, Paycheck, and Securities you must use the add button available on the right side of their respective field. It must be selected to be registered as a value.

After all value is inserted, press the SAVE button and hit REPORT to see the results. Inside the report, use the left and right button to browse inserted data(which is each coressponding data stored inside a class e.g class1{Erwin,Male,Geek}, class2{John,Male,Genius}, etc)

The problems are:
-I couldn't figure out how to convert the checkedlistbox items on Form1 into a listbox in FormReport. I've tried to convert to string and array but no result.

-How to initialize the list and to access the list. Also how to implement the value changes in formReport?

The Solution(VC# 2010) Click Here

Any help regarding this one? Thanks in advance.

Try this :

  1. Add this to 'Customer.cs' :

        List<string> Sec = new List<string>(); 
    
        public List<string> GetSec()
        {
            return Sec;
        }
    
        public void SetSec(string value)
        {
            Sec.Add(value);
        }
    
        public void ClearSecList()
        {
            Sec.Clear();
        }
    
  2. Add this to 'Form1.cs' :

       void GetCheckedBoxes()
       {
            user.ClearSecList();
            for (int i = 0; i < this.checkedListBoxSecurity.CheckedItems.Count; i++) {
                user.SetSec(this.checkedListBoxSecurity.CheckedItems[i].ToString());  
            }                              
        }
    
  3. Add this to 'button1_Click' (in Form1.cs) :

        GetCheckedBoxes();
        report.SetSecList(user.GetSec());  
    
  4. Add this to FormReport.cs

     public void SetSecList(List<string> value)
        {
            this.listBoxJaminan.DataSource = value;            
        }
    
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.