Beispiel #1
0
        static void CheckedListBox_OnSelectedIndexChanged(object sender, EventArgs e)
        {
            System.Windows.Forms.CheckedListBox lCheck = (System.Windows.Forms.CheckedListBox)sender;

            if (lCheck.SelectedItem.ToString().Equals("Selecionar Todos") && lCheck.GetItemChecked(0))
            {
                for (int i = 0; i < ((System.Windows.Forms.CheckedListBox)sender).Items.Count; i++)
                {
                    lCheck.SetItemChecked(i, true);

                    if (!lCheck.SelectedItem.ToString().Equals("Selecionar Todos"))
                    {
                        gListaClienteSelecionadosFiltro.Add((int)(lCheck.Items[i]));
                    }
                }
            }
            else if (lCheck.SelectedItem.ToString().Equals("Selecionar Todos") && !lCheck.GetItemChecked(0))
            {
                for (int i = 0; i < ((System.Windows.Forms.CheckedListBox)sender).Items.Count; i++)
                {
                    lCheck.SetItemChecked(i, false);

                    if (!lCheck.SelectedItem.ToString().Equals("Selecionar Todos"))
                    {
                        gListaClienteSelecionadosFiltro.Remove((int)(lCheck.Items[i]));
                    }
                }
            }
            else
            {
                if (!lCheck.SelectedItem.ToString().Equals("Selecionar Todos"))
                {
                    int lConta = Convert.ToInt32(lCheck.SelectedItem);

                    if (gListaClienteSelecionadosFiltro.Contains(lConta))
                    {
                        gListaClienteSelecionadosFiltro.Remove(lConta);
                    }
                    else
                    {
                        gListaClienteSelecionadosFiltro.Add(lConta);
                    }
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Finds all the items in a <see cref="System.Windows.Forms.CheckedListBox"/> that are checked and have non-null values
        /// </summary>
        /// <param name="checkedListBox">A <see cref="System.Windows.Forms.CheckedListBox"/> to operate on. </param>
        /// <returns>All the items in a <see cref="System.Windows.Forms.CheckedListBox"/> that are checked and have non-null values.</returns>
        public static IEnumerable <string> GetNonNullCheckedItemValues(this System.Windows.Forms.CheckedListBox checkedListBox)
        {
            for (var id = 0; id <= (checkedListBox.Items.Count - 1); id++)
            {
                if (!checkedListBox.GetItemChecked(id))
                {
                    continue;
                }

                var selectedItemString = checkedListBox.Items[id]?.ToString();
                if (string.IsNullOrWhiteSpace(selectedItemString))
                {
                    continue;
                }

                yield return(selectedItemString);
            }
        }