2
Answers

check box liost control in c#

Maneesh A N

Maneesh A N

10y
701
1
HI

       I need to save and return certain values from check box list in c#
            
Answers (2)
0
Hemant Srivastava
NA 9k 2.8m 10y


Here is a sample code for your help

In this I created a Form named 'MyChildForm' that has CheckBoxListControl where user could select the multiple items on CheckBoxList

OnClicking 'OK' button, form gets closed and all the checked items are saved into a property named 'ListOfCheckedItems'


    public partial class MyChildForm : Form
    {
        private List<string> _listOfCheckedItems;

        public List<string> ListOfCheckedItems
        {
            get { return _listOfCheckedItems; }
            set { _listOfCheckedItems = value; }
        }

        public MyChildForm()
        {
            InitializeComponent();
        }

        private void Oct_2014_Load(object sender, EventArgs e)
        {
            _listOfCheckedItems = new List<string>();
        }

        // Ok Button
        private void button1_Click(object sender, EventArgs e)
        {
            //One by one it will fetch the items from the checked Items of the Checkedlistbox.
            foreach (var item in checkedListBox1.CheckedItems)
            {
                //Add the retrieved item into the our List.
                _listOfCheckedItems.Add(item.ToString());
            }
            this.Close();
        }
    }

On some other form, I call the ChildForm and retrieves all the checked values into a List<string> (list)


            MyChildForm oMyChildForm = new MyChildForm();
            oMyChildForm.ShowDialog();
            List<string> list = oMyChildForm.ListOfCheckedItems;

Hop it might help you to solve your problem



0
Hemant Srivastava
NA 9k 2.8m 10y

Could you explain your problem in more detail like ...where do you want to save the values, returned values etc?
Next Recommended Forum