/[gr2lib]/trunk/gr2lib/core/ui/typeeditors/ComboValueSelector.cs
ViewVC logotype

Annotation of /trunk/gr2lib/core/ui/typeeditors/ComboValueSelector.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 186 - (hide annotations) (download)
Sat Jul 24 02:23:18 2010 UTC (9 years, 6 months ago) by william
File size: 2655 byte(s)
continue to add xml documentation

1 william 160 using System;
2     using System.Collections.Generic;
3     using System.ComponentModel;
4     using System.Drawing;
5     using System.Data;
6     using System.Linq;
7     using System.Text;
8     using System.Windows.Forms;
9     using gr2lib.core.ui.rigeditor.interfaces;
10     using gr2lib.core.helpers;
11    
12     namespace gr2lib.core.ui.typeeditors
13     {
14 william 186 /// <summary>
15     /// ComboValueSelector Editor
16     /// </summary>
17     /// <typeparam name="ENUM_TYPE">The enum to use</typeparam>
18     /// <typeparam name="ENUM_BASE_TYPE">the type that the enum uses (i.e. int, uint, etc)</typeparam>
19     public partial class ComboValueSelector<ENUM_TYPE, ENUM_BASE_TYPE> : BaseEditorComboBox<NameValuePair<string, ENUM_TYPE>>
20 william 160 where ENUM_BASE_TYPE : IConvertible
21     {
22 william 186 /// <summary>
23     /// default constructor
24     /// </summary>
25 william 160 public ComboValueSelector()
26 william 186 : base()
27 william 160 {
28     InitializeComponent();
29     this.Value = new NameValuePair<string, ENUM_TYPE>("", default(ENUM_TYPE));
30     this.PopulateComboBox();
31     this.SelectedIndexChanged +=new EventHandler(ComboValueSelector_SelectedIndexChanged);
32     }
33 william 186 /// <summary>
34     /// default constructor, specifying an object of type
35     /// </summary>
36     /// <param name="value"></param>
37 william 160 public ComboValueSelector(object value)
38 william 186 : base(value)
39 william 160 {
40     InitializeComponent();
41     this.Value = (NameValuePair<string, ENUM_TYPE>)value;
42     this.PopulateComboBox();
43     this.SelectedIndexChanged += new EventHandler(ComboValueSelector_SelectedIndexChanged);
44     }
45    
46     private void PopulateComboBox()
47     {
48     int curr_value = Convert.ToInt32(Value.Value);
49     foreach (int value in Enum.GetValues(typeof(ENUM_TYPE)))
50     {
51     string name = Enum.GetName(typeof(ENUM_TYPE), value);
52     this.Items.Add(name + " {" + value.ToString() + "}");
53     if (curr_value == value) this.SelectedIndex = value;
54     }
55     }
56    
57     private void ComboValueSelector_SelectedIndexChanged(object sender, EventArgs e)
58     {
59     string[] lookup = this.Items[this.SelectedIndex].ToString().Replace(" ","").Split('{');
60     string name = lookup[0];
61     int value = Convert.ToInt32(lookup[1].Replace("}",""));
62     this.Value = new NameValuePair<string, ENUM_TYPE>(name, ValueToEnum(value));
63     }
64    
65 william 186 private ENUM_TYPE ValueToEnum(int number)
66 william 160 {
67     return (ENUM_TYPE)Enum.ToObject(typeof(ENUM_TYPE), number);
68     }
69     }
70     }

  ViewVC Help
Powered by ViewVC 1.1.22