Beispiel #1
0
        /// <summary>
        /// Swap places of two items
        /// </summary>
        /// <param name="lstBox">The calling CheckedListBox</param>
        /// <param name="indexA">Index of forst item</param>
        /// <param name="indexB">Index of second item</param>
        /// <returns>CheckedListBox with new item order</returns>
        public static System.Windows.Forms.CheckedListBox SwapItems(this System.Windows.Forms.CheckedListBox lstBox, int indexA, int indexB)
        {
            if (indexB > -1 && indexB < lstBox.Items.Count)
            {
                object tmpItem = lstBox.Items[indexA];
                lstBox.Items[indexA] = lstBox.Items[indexB];
                lstBox.Items[indexB] = tmpItem;

                var stateA = lstBox.GetItemCheckState(indexA);
                var stateB = lstBox.GetItemCheckState(indexB);
                lstBox.SetItemCheckState(indexB, stateA);
                lstBox.SetItemCheckState(indexA, stateB);
            }
            return(lstBox);
        }
Beispiel #2
0
 public void InitAllConfigsCLB(System.Windows.Forms.CheckedListBox _ListBox)
 {
     {
         _ListBox.Items.Clear();
         var orderedConfigValues = ConfigValues.OrderBy(ConfigValueSort);
         foreach (var configValue in orderedConfigValues)
         {
             _ListBox.Items.Add(configValue.Key + (configValue.Value.Item1 == "enabled(auto)" ? "(Auto Enabled)" : ""), (configValue.Value.Item1 != "disabled"));
         }
     }
     _ListBox.CheckOnClick = true;
     ConfigValuesChanged  += (string _ConfigName, string _ConfigValue) =>
     {
         _ListBox.BeginInvoke(new Action(() =>
         {
             if (_ConfigName != "ALL_CONFIG_VALUES_CHANGED_UPDATE_ALL")
             {
                 for (int i = 0; i < _ListBox.Items.Count; ++i)
                 {
                     string item = (string)_ListBox.Items[i];
                     if (item.StartsWith(_ConfigName) == true)
                     {
                         if (item == _ConfigName + "(Auto Enabled)" || item == _ConfigName)
                         {
                             if (_ListBox.CheckedIndices.Contains(i) != (_ConfigValue != "disabled"))
                             {
                                 _ListBox.SetItemCheckState(i, (_ConfigValue != "disabled" ? System.Windows.Forms.CheckState.Checked : System.Windows.Forms.CheckState.Unchecked));
                             }
                             _ListBox.Items[i] = _ConfigName;
                             return;
                         }
                     }
                 }
             }
             else
             {
                 _ListBox.Items.Clear();
                 var orderedConfigValues = ConfigValues.OrderBy(ConfigValueSort);
                 foreach (var configValue in orderedConfigValues)
                 {
                     _ListBox.Items.Add(configValue.Key + (configValue.Value.Item1 == "enabled(auto)" ? "(Auto Enabled)" : ""), (configValue.Value.Item1 != "disabled"));
                 }
                 _ListBox.Invalidate();
             }
         }));
     };
     _ListBox.ItemCheck += EventAllConfigsCLB_ItemCheck;
 }