293 lines
7.8 KiB
C#
293 lines
7.8 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.ComponentModel;
|
|
using System.Drawing;
|
|
using System.Data;
|
|
using System.Windows.Forms;
|
|
|
|
namespace GZTW.WinForm.Controls
|
|
{
|
|
/// <summary>
|
|
/// Summary for needmoredatahandler
|
|
/// </summary>
|
|
public delegate void NeedMoreDataHandler();
|
|
|
|
/// <summary>
|
|
/// Summary description for GZUltraComboEditor.
|
|
/// </summary>
|
|
public class GZUltraComboEditor : Infragistics.Win.UltraWinEditors.UltraComboEditor
|
|
{
|
|
/// <summary>
|
|
/// Required designer variable.
|
|
/// </summary>
|
|
private System.ComponentModel.Container components = null;
|
|
public GZUltraComboEditor()
|
|
{
|
|
// This call is required by the Windows.Forms Form Designer.
|
|
InitializeComponent();
|
|
|
|
//Do construction only in runtime
|
|
//if(System.Diagnostics.Process.GetCurrentProcess().ProcessName != "devenv")// OR if (LicenseManager.UsageMode == LicenseUsageMode.Designtime)
|
|
if (LicenseManager.UsageMode != LicenseUsageMode.Designtime) //seems to be fastest checking method
|
|
{
|
|
|
|
if(bAllowEmptySelection)
|
|
{
|
|
//Case 324
|
|
//viEmpty=this.Items.Add(Guid.Empty,"-");
|
|
//viEmpty.Appearance.BackColor=System.Drawing.SystemColors.GrayText;
|
|
//this.SelectedItem=viEmpty;
|
|
|
|
//10-dec-2008 commented out above and changed to this see emptyvaluelistitem for why
|
|
Items.Add(EmptyValueListItem);//added later was missing
|
|
this.SelectedItem = EmptyValueListItem;
|
|
}
|
|
|
|
//Case 321
|
|
this.DropDownStyle = Infragistics.Win.DropDownStyle.DropDown;
|
|
|
|
this.AutoCompleteMode = Infragistics.Win.AutoCompleteMode.SuggestAppend;
|
|
this.LimitToList=true;
|
|
|
|
|
|
this.SortStyle = Infragistics.Win.ValueListSortStyle.Ascending;
|
|
this.MaxDropDownItems=25;
|
|
}
|
|
|
|
}
|
|
|
|
#region public properties
|
|
|
|
|
|
private Infragistics.Win.ValueListItem viEmpty=null;
|
|
private Infragistics.Win.UltraWinEditors.UltraComboEditor ultraComboEditor1;
|
|
|
|
/// <summary>
|
|
/// Built in default empty value list item
|
|
/// Used to check for selection etc
|
|
/// not visible in property window of designer
|
|
/// </summary>
|
|
[Browsable(false)]
|
|
public Infragistics.Win.ValueListItem EmptyValueListItem
|
|
{
|
|
get
|
|
{
|
|
//10-dec-2008 added this because
|
|
//it was throwing an exception in visual studio forms designer
|
|
//when attempt to change the AllowEmpty property from false to true
|
|
if(viEmpty==null)
|
|
{
|
|
viEmpty = new Infragistics.Win.ValueListItem(Guid.Empty, "-");
|
|
viEmpty.Appearance.BackColor = System.Drawing.SystemColors.GrayText;
|
|
}
|
|
return viEmpty;
|
|
}
|
|
}
|
|
|
|
private bool bAllowEmptySelection=true;
|
|
/// <summary>
|
|
/// Allow or disallow guid.empty as an option
|
|
/// </summary>
|
|
[Bindable(true), Category("GZ Options"),
|
|
DefaultValue(true),
|
|
Description("False=will not offer an empty choice (Guid.Empty) or allow one. True=will have by default a Guid.Empty selection.")]
|
|
public bool AllowEmptySelection
|
|
{
|
|
get
|
|
{
|
|
return bAllowEmptySelection;
|
|
}
|
|
set
|
|
{
|
|
bAllowEmptySelection=value;
|
|
if(value==false)
|
|
{//remove empty value from list
|
|
if(viEmpty!=null)
|
|
this.Items.Remove(viEmpty);
|
|
}
|
|
else
|
|
{//Put empty value back in list if necessary
|
|
if(!this.Items.Contains(viEmpty))
|
|
this.Items.Add(this.viEmpty);
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// Clean up any resources being used.
|
|
/// </summary>
|
|
protected override void Dispose( bool disposing )
|
|
{
|
|
|
|
|
|
//this crept up for no apparent reason during development of v7
|
|
//when the clientselector form is disposed of while in a workorder it throws the illegal cross thread call in base.dispose below.
|
|
|
|
if( disposing )
|
|
{
|
|
if( components != null )
|
|
components.Dispose();
|
|
}
|
|
|
|
base.Dispose( disposing );
|
|
}
|
|
|
|
#region Component Designer generated code
|
|
/// <summary>
|
|
/// Required method for Designer support - do not modify
|
|
/// the contents of this method with the code editor.
|
|
/// </summary>
|
|
private void InitializeComponent()
|
|
{
|
|
this.ultraComboEditor1 = new Infragistics.Win.UltraWinEditors.UltraComboEditor();
|
|
((System.ComponentModel.ISupportInitialize)(this.ultraComboEditor1)).BeginInit();
|
|
((System.ComponentModel.ISupportInitialize)(this)).BeginInit();
|
|
this.SuspendLayout();
|
|
//
|
|
// ultraComboEditor1
|
|
//
|
|
this.ultraComboEditor1.Location = new System.Drawing.Point(0, 0);
|
|
this.ultraComboEditor1.Name = "ultraComboEditor1";
|
|
this.ultraComboEditor1.Size = new System.Drawing.Size(144, 21);
|
|
this.ultraComboEditor1.TabIndex = 0;
|
|
this.ultraComboEditor1.Text = "ultraComboEditor1";
|
|
((System.ComponentModel.ISupportInitialize)(this.ultraComboEditor1)).EndInit();
|
|
((System.ComponentModel.ISupportInitialize)(this)).EndInit();
|
|
this.ResumeLayout(false);
|
|
|
|
}
|
|
#endregion
|
|
|
|
protected override void OnPaint(PaintEventArgs pe)
|
|
{
|
|
//
|
|
|
|
// Calling the base class OnPaint
|
|
base.OnPaint(pe);
|
|
}
|
|
|
|
|
|
|
|
|
|
#region Events and customization
|
|
|
|
/// <summary>
|
|
/// Get me some data...STAT!
|
|
/// </summary>
|
|
public event NeedMoreDataHandler NeedMoreData;
|
|
|
|
/// <summary>
|
|
/// Need more data so get it.
|
|
/// </summary>
|
|
protected virtual void OnNeedMoreData()
|
|
{
|
|
//case 1484
|
|
if (this.ReadOnly || this.Enabled == false)
|
|
return;
|
|
|
|
if(NeedMoreData!=null)
|
|
{NeedMoreData();}
|
|
|
|
}
|
|
|
|
|
|
//Added for infragistics 7.2 upgrade as argument signature of event
|
|
//has apparently changed from what it used to be below
|
|
protected override void OnBeforeDropDown(CancelEventArgs args)
|
|
{
|
|
//case 1484
|
|
if (this.ReadOnly || this.Enabled == false)
|
|
return;
|
|
|
|
if (this.Items.Count < 3)
|
|
OnNeedMoreData();
|
|
base.OnBeforeDropDown(args);
|
|
}
|
|
|
|
//protected override void OnBeforeDropDown(object sender, CancelEventArgs args)
|
|
//{
|
|
// if(this.Items.Count < 3)
|
|
// OnNeedMoreData();
|
|
|
|
// base.OnBeforeDropDown (sender, args);
|
|
//}
|
|
|
|
|
|
/// <summary>
|
|
/// Override onkeydown
|
|
/// Get rid of leading space so autocomplete will work
|
|
/// Fill list if it's empty
|
|
/// </summary>
|
|
/// <param name="e"></param>
|
|
protected override void OnKeyDown(KeyEventArgs e)
|
|
{
|
|
if(this.ReadOnly || this.Enabled==false)
|
|
return;
|
|
|
|
|
|
|
|
if(e.KeyData!= Keys.Tab)
|
|
{
|
|
//Case 321
|
|
//commented out the following, not required with changes for case 321
|
|
|
|
//remove leading space unless that's the character typed
|
|
//if(e.KeyData!=Keys.Space)
|
|
// this.Text=this.Text.TrimStart(' ');
|
|
|
|
if(this.Items.Count < 3)
|
|
OnNeedMoreData();
|
|
|
|
}
|
|
else
|
|
{
|
|
if(bAllowEmptySelection)
|
|
{
|
|
//check if the user wiped out all the text thus
|
|
//indicating no selection and if so then
|
|
//force the empty selection automatically
|
|
if(this.Text=="")
|
|
{
|
|
this.SelectedItem=this.viEmpty;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
base.OnKeyDown (e);
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// Clears all but the default guid empty item from
|
|
/// the value item list unless empty items are not allowed
|
|
/// in which case it clears them all
|
|
/// </summary>
|
|
public void ClearList()
|
|
{
|
|
|
|
this.Items.Clear();
|
|
if(bAllowEmptySelection)
|
|
viEmpty=this.Items.Add(Guid.Empty,"-");//Case 324
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|