using System;
|
using System.Collections.Generic;
|
using System.Text;
|
using System.Windows.Forms;
|
|
namespace HotelPms.Share.Windows.Util
|
{
|
public class ComboBoxItem
|
{
|
private string m_Key = string.Empty;
|
|
public string Key
|
{
|
get { return m_Key; }
|
set { m_Key = value; }
|
}
|
|
private string m_Text = string.Empty;
|
|
public string Text
|
{
|
get { return m_Text; }
|
set { m_Text = value; }
|
}
|
|
private object m_Tag = null;
|
|
public object Tag
|
{
|
get { return m_Tag; }
|
set { m_Tag = value; }
|
}
|
|
public ComboBoxItem(string key, string text)
|
{
|
this.m_Key = key;
|
this.m_Text = text;
|
}
|
|
public override string ToString()
|
{
|
return m_Text;
|
}
|
|
public static void AddComboBox(ComboBox obj, Type type)
|
{
|
AddComboBox(obj, type, false, -1);
|
}
|
|
public static void AddComboBox(ComboBox obj, Type type, bool useBlank)
|
{
|
AddComboBox(obj, type, useBlank, -1);
|
}
|
|
public static void AddComboBox(ComboBox obj, Type type, bool useBlank, int defID)
|
{
|
int selIndex = 0;
|
obj.Items.Clear();
|
int i = 0;
|
if (useBlank)
|
{
|
obj.Items.Add(new ComboBoxItem("-1", string.Empty));
|
i++;
|
}
|
|
foreach (object item in Enum.GetValues(type))
|
{
|
int id = (int)item;
|
string name = item.ToString();
|
if (name.Contains("_"))
|
{
|
string[] items = name.Split(new char[] { '_' });
|
if (items.Length == 2) { name = string.Format("{0}({1})", items[0], items[1]); }
|
}
|
|
obj.Items.Add(new ComboBoxItem(id.ToString(), name));
|
if (id == defID) { selIndex = i; }
|
i++;
|
}
|
obj.SelectedIndex = selIndex;
|
}
|
}
|
}
|