ATMLCommonLibrary.forms.CheckedListForm.AddListItem C# (CSharp) Method

AddListItem() public method

public AddListItem ( object item, bool selected ) : void
item object
selected bool
return void
        public void AddListItem(object item, bool selected )
        {
            ListViewItem lvi = null;
            listItems.Add(item);
            if (propertyName == null)
            {
                lvi = new ListViewItem(item.ToString());
            }
            else
            {
                System.Reflection.PropertyInfo pi = item.GetType().GetProperty(propertyName);
                lvi = new ListViewItem((String) pi.GetValue(item, null));
            }
            lvi.Tag = item;
            chkList.Items.Add(lvi, selected );
        }

Usage Example

        private void btnSelectOuts_Click(object sender, EventArgs e)
        {
            if (_availableOuts != null)
            {
                //----------------------------------------------------------------------------------//
                //--- Pass in "name" as the property name from the port to use as the list value ---//
                //----------------------------------------------------------------------------------//
                var form = new CheckedListForm("name");
                foreach (Port port in _availableOuts)
                {
                    if (port.direction == PortDirection.Output
                        || port.direction == PortDirection.BiDirectional)
                    {
                        form.AddListItem(port, edtOut.Text.Contains(port.name));
                    }
                }

                if (DialogResult.OK == form.ShowDialog())
                {
                    List<object> selectedList = form.SelectedIems;
                    //---------------------------------//
                    //--- Clear any existing inputs ---//
                    //---------------------------------//
                    edtOut.Text = "";

                    //------------------------------------------------------//
                    //--- Walk each checked input from checked list form ---//
                    //------------------------------------------------------//
                    foreach (object item in selectedList)
                    {
                        var port = (Port) item;
                        //----------------------------------------------------------------------------------//
                        //--- Add output items to in line separated by a space (backwards compatability) ---//
                        //----------------------------------------------------------------------------------//
                        edtOut.Text += port.name + " ";
                    }
                }
            }
        }
All Usage Examples Of ATMLCommonLibrary.forms.CheckedListForm::AddListItem