コード例 #1
0
        private void UpdateHotkeyList()
        {
            HotkeyList.BeginUpdate();
            var idx = HotkeyList.SelectedIndices.Count == 0 ? 0 : HotkeyList.SelectedIndices[0];

            HotkeyList.Items.Clear();
            foreach (var hotkey in _hotkeys.OrderBy(x => x.ID))
            {
                var def = Hotkeys.GetHotkeyDefinition(hotkey.ID);
                HotkeyList.Items.Add(new ListViewItem(new[]
                {
                    def.Name,
                    def.Description,
                    String.IsNullOrWhiteSpace(hotkey.HotkeyString)
                                                                  ? "<unassigned>"
                                                                  : hotkey.HotkeyString
                })
                {
                    Tag = hotkey
                });
            }
            HotkeyList.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
            if (idx >= 0 && idx < HotkeyList.Items.Count)
            {
                HotkeyList.Items[idx].Selected = true;
            }
            HotkeyList.EndUpdate();

            HotkeyActionList.BeginUpdate();
            idx = HotkeyActionList.SelectedIndex;
            HotkeyActionList.Items.Clear();
            foreach (var def in Hotkeys.GetHotkeyDefinitions().OrderBy(x => x.ID))
            {
                HotkeyActionList.Items.Add(def);
            }
            if (idx < 0 || idx >= HotkeyActionList.Items.Count)
            {
                idx = 0;
            }
            HotkeyActionList.SelectedIndex = idx;
            HotkeyActionList.EndUpdate();
        }