Is the following possible in any way?
public enum Country {
"United Kingdom" = 1
}
--- neteject.com - Internet Solutions ---
public enum Country {
"United Kingdom" = 1
}
--- neteject.com - Internet Solutions ---
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Hashtable ht = new Hashtable();
ht.Add("United Kingdom",1);
ht.Add("Brazil", 25);
ht.Add("USA",19);
ht.Add(1,"United Kingdom");
ht.Add(25,"Brazil");
ht.Add(19,"USA");
object val=null;
object key=null;
if (ht.ContainsKey("United Kingdom"))
{
val = ht["United Kingdom"];
}
if (ht.ContainsValue(19))
{
key = ht[19];
}
/// <summary>
/// Specifies the _Format for displaying and printing numbers, dates, times, and text.
/// </summary>
[Bindable(true), Category("Text"), DefaultValue(""), Editor(typeof(FormatEnum), typeof(UITypeEditor)),
Description("Specifies the _Format for displaying and printing numbers, dates, times, and text.")]
public string Format
{
get{return this._Format;}
set
{
if (this._Format != value)
{
this._Format = value;
//this.Mask = ReplaceFormatCharacters(value);
}
}
}
#region enum designer
/// <summary>
/// Klasa vo koja se menuva propertyto vo sloboden tekst
/// </summary>
public class FormatEnum : UITypeEditor
{
private IWindowsFormsEditorService edSvc = null;
// private ToolTip tooltipControl;
private ListBox lst;
private string[] formats = {"Only Text", "Only numeric"};
/// <summary>
/// Internal class used for storing custom data in listviewitems
/// </summary>
internal class lbItem
{
private string str;
private int value;
private string tooltip;
/// <summary>
/// Creates a new instance of the <c>lbItem</c>
/// </summary>
/// <param name="str">The string to display in the <c>ToString</c> method.
/// It will contains the name of the flag</param>
/// <param name="value">The integer value of the flag</param>
/// <param name="tooltip">The tooltip to display in the <see cref="CheckedListBox"/></param>
public lbItem(string str, int value, string tooltip)
{
this.str = str;
this.value = value;
this.tooltip = tooltip;
}
/// <summary>
/// Gets the int value for this item
/// </summary>
public int Value
{
get{return value;}
}
/// <summary>
/// Gets the tooltip for this item
/// </summary>
public string Tooltip
{
get{return tooltip;}
}
/// <summary>
/// Gets the name of this item
/// </summary>
/// <returns>The name passed in the constructor</returns>
public override string ToString()
{
return str;
}
}
/// <summary>
/// Overrides the method used to provide basic behaviour for selecting editor.
/// Shows our custom control for editing the value.
/// </summary>
/// <param name="context">The context of the editing control</param>
/// <param name="provider">A valid service provider</param>
/// <param name="value">The current value of the object to edit</param>
/// <returns>The new value of the object</returns>
public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, System.IServiceProvider provider, object value)
{
if (context != null
&& context.Instance != null
&& provider != null)
{
edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
if (edSvc != null)
{
lst = new ListBox();
lst.SelectedValueChanged += new EventHandler(ValueChanged);
lst.Items.AddRange(formats);
lst.Text = (string)lst.Items[lst.FindString((string)value)];
edSvc.DropDownControl(lst);
return lst.Text;
}
}
return value;
}
/// <summary>
/// Shows a dropdown icon in the property editor
/// </summary>
/// <param name="context">The context of the editing control</param>
/// <returns>Returns <c>UITypeEditorEditStyle.DropDown</c></returns>
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
if (context != null && context.Instance != null)
return UITypeEditorEditStyle.DropDown;
else
return base.GetEditStyle(context);
}
private bool handleLostfocus = false;
/// <summary>
/// When got the focus, handle the lost focus event.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnMouseDown(object sender, MouseEventArgs e)
{
if(!handleLostfocus && lst.ClientRectangle.Contains(lst.PointToClient(new Point(e.X, e.Y))))
{
lst.SelectedIndexChanged += new EventHandler(this.ValueChanged);
handleLostfocus = true;
}
}
/// <summary>
/// Close the dropdowncontrol when the user has selected a value
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ValueChanged(object sender, EventArgs e)
{
if (edSvc != null)
{
edSvc.CloseDropDown();
}
}
}
#endregion