Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OKB/HeuristicLab.OKB.AlgorithmHost/SelectItemDialog.cs @ 7077

Last change on this file since 7077 was 4311, checked in by swagner, 14 years ago

Integrated OKB clients for HL 3.3 (#1166)

File size: 2.5 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Data;
5using System.Drawing;
6using System.Linq;
7using System.Text;
8using System.Windows.Forms;
9
10namespace HeuristicLab.OKB.AlgorithmHost {
11  public partial class SelectItemDialog : Form {
12
13    public object Item { get; private set; }
14
15    public SelectItemDialog() {
16      InitializeComponent();
17      itemsListView.SmallImageList = new ImageList();     
18    }
19
20    private Dictionary<string, ListViewGroup> groups = new Dictionary<string, ListViewGroup>();
21
22    public void Clear() {
23      itemsListView.Clear();
24      itemsListView.Groups.Clear();
25      groups.Clear();
26      itemsListView.SmallImageList = new ImageList();
27    }
28
29    public void AddItem(string name, string description, string groupName, object o, Image icon) {
30      ListViewGroup group = null;
31      if (groupName != null) {
32        groups.TryGetValue(groupName, out group);
33        if (group == null) {
34          group = new ListViewGroup(groupName, groupName);         
35          groups[groupName] = group;
36          itemsListView.Groups.Add(group);
37        }
38      }
39      ListViewItem item;
40      if (group != null)
41        item = new ListViewItem(new string[] { name, description }, group);
42      else
43        item = new ListViewItem(new string[] { name, description });
44      if (icon != null) {
45        itemsListView.SmallImageList.Images.Add(icon);
46        item.ImageIndex = itemsListView.SmallImageList.Images.Count - 1;           
47      }
48      item.Tag = o;
49      itemsListView.Items.Add(item);           
50    }
51
52    private void SelectItemDialog_Shown(object sender, EventArgs e) {
53      Item = null;
54      DialogResult = DialogResult.None;
55    }
56
57    private void itemsListView_SelectedIndexChanged(object sender, EventArgs e) {
58      okButton.Enabled = itemsListView.SelectedItems.Count == 1;
59    }
60
61    private void okButton_Click(object sender, EventArgs e) {
62      if (itemsListView.SelectedItems.Count == 1) {
63        Item = itemsListView.SelectedItems[0].Tag;
64        DialogResult = DialogResult.OK;
65        Close();
66      }
67    }
68
69    private void cancelButton_Click(object sender, EventArgs e) {
70      DialogResult = DialogResult.Cancel;
71      Close();
72    }
73
74    private void itemsListView_DoubleClick(object sender, EventArgs e) {
75      if (itemsListView.SelectedItems.Count == 1) {
76        Item = itemsListView.SelectedItems[0].Tag;
77        DialogResult = DialogResult.OK;
78        Close();
79      }
80    }   
81
82  }
83}
Note: See TracBrowser for help on using the repository browser.