Changeset 6


Ignore:
Timestamp:
Apr 4, 2019, 10:21:48 AM (6 years ago)
Author:
chronos
Message:
  • Fixed: Prompt listbox error if initial value was set to null.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Common/Prompt.cs

    r1 r6  
    152152            };
    153153            Label textLabel = new Label() { Left = 50, Top = 20, AutoSize = true, Text = text };
     154            Button confirmation = new Button()
     155            {
     156                Text = "Ok",
     157                Left = 350,
     158                Width = 100,
     159                Top = 70 + dataSize,
     160                DialogResult = DialogResult.OK,
     161                Anchor = AnchorStyles.Bottom | AnchorStyles.Right
     162            };
     163            confirmation.Click += (sender, e) => { prompt.Close(); };
    154164            ListBox listBox = new ListBox() { Left = 50, Top = 44, Width = 400, Height = dataSize,
    155165                Anchor = AnchorStyles.Bottom | AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Left
    156166            };
     167            listBox.SelectedIndexChanged += (sender, e) =>
     168            {
     169                confirmation.Enabled = listBox.SelectedItems.Count > 0;
     170            };
    157171            listBox.Items.AddRange(states);
    158             int itemIndex = listBox.Items.IndexOf(initialValue);
     172            confirmation.Enabled = listBox.SelectedItems.Count > 0;
     173            listBox.DoubleClick += (sender, e) => { confirmation.PerformClick(); };
     174            int itemIndex = -1;
     175            if (initialValue != null) itemIndex = listBox.Items.IndexOf(initialValue);
    159176            if (itemIndex >= 0)
    160177            {
     
    165182                listBox.SelectedIndex = 0;
    166183            }
    167             Button confirmation = new Button() { Text = "Ok", Left = 350, Width = 100, Top = 70 + dataSize,
    168                 DialogResult = DialogResult.OK, Anchor = AnchorStyles.Bottom | AnchorStyles.Right };
    169             confirmation.Click += (sender, e) => { prompt.Close(); };
    170             listBox.DoubleClick += (sender, e) => { confirmation.PerformClick(); };
    171184
    172185            prompt.Controls.Add(listBox);
Note: See TracChangeset for help on using the changeset viewer.