| [ToolboxItem(false)] |
| publicclassTextBox:System.Windows.Forms.TextBox |
| { |
| publicTextBox():base() |
| { |
| } |
|
| publicstringDisplayMember{get;set;} |
|
| publicstringValueMember{get;set;} |
| |
| } |
|
|
| [ToolboxItem(false)] |
| publicclassButton:System.Windows.Forms.Button |
| { |
| publicButton():base() |
| { |
| } |
|
| publicstringFormName{get;set;} |
| } |
|
| [ToolboxItem(false)] |
| publicpartialclassLookUp:UserControl |
| { |
| publicLookUp() |
| { |
| InitializeComponent(); |
| } |
|
| publicTextBoxLookUPTextBox |
| { |
| get |
| { |
| returnthis.lookUpTextBox; |
| } |
| } |
|
| publicButtonLookUPButton |
| { |
| get |
| { |
| returnthis.lookUpButton; |
| } |
| } |
|
| publicboolReadOnly{get;set;} |
|
| publicnewstringText |
| { |
| get |
| { |
| returnthis.lookUpTextBox.Text; |
| } |
| set |
| { |
| this.lookUpTextBox.Text=value; |
| } |
| } |
| } |
|
| publicclassCustomLookUpCell:DataGridViewTextBoxCell |
| { |
| publicCustomLookUpCell() |
| { |
| } |
|
| publicoverridevoidInitializeEditingControl(introwIndex,objectinitialFormattedValue,DataGridViewCellStyledataGridViewCellStyle) |
| { |
| base.InitializeEditingControl(rowIndex,initialFormattedValue,dataGridViewCellStyle); |
|
| CustomLookUpConrolcustomLookUpConrol=this.DataGridView.EditingControlasCustomLookUpConrol; |
| if(this.Value!=null) |
| customLookUpConrol.LookUPTextBox.Text=this.Value.ToString(); |
|
| CustomLookUpColumncustomLookUpColumn=this.OwningColumnasCustomLookUpColumn; |
| customLookUpConrol.LookUPButton.FormName=string.Format("{0}{1}{2}",customLookUpColumn.NameSpace,".",customLookUpColumn.FormName); |
| customLookUpConrol.LookUPTextBox.DisplayMember=customLookUpColumn.DisplayMember; |
| customLookUpConrol.LookUPTextBox.ValueMember=customLookUpColumn.ValueMember; |
| } |
|
| publicoverrideTypeEditType |
| { |
| get |
| { |
| returntypeof(CustomLookUpConrol); |
| } |
| } |
|
| publicoverrideTypeValueType |
| { |
| get |
| { |
| returntypeof(string); |
| } |
| } |
|
| publicoverrideobjectDefaultNewRowValue |
| { |
| get |
| { |
| returnstring.Empty; |
| } |
| } |
|
| privateCustomLookUpConrolEditingCustomLookUpConrol |
| { |
| get |
| { |
| returnthis.DataGridView.EditingControlasCustomLookUpConrol; |
| } |
| } |
|
| publicoverrideobjectClone() |
| { |
| CustomLookUpCellcustomLookUpCell=base.Clone()asCustomLookUpCell; |
| returncustomLookUpCell; |
| } |
|
| publicoverrideobjectParseFormattedValue(objectformattedValue,DataGridViewCellStylecellStyle,System.ComponentModel.TypeConverterformattedValueTypeConverter,System.ComponentModel.TypeConvertervalueTypeConverter) |
| { |
| returnbase.ParseFormattedValue(formattedValue,cellStyle,formattedValueTypeConverter,valueTypeConverter); |
| } |
| } |
|
| publicclassCustomLookUpColumn:DataGridViewColumn |
| { |
| publicCustomLookUpColumn() |
| :base(newCustomLookUpCell()) |
| { |
|
| } |
|
|
| [Browsable(false),DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] |
| publicoverrideDataGridViewCellCellTemplate |
| { |
| get |
| { |
| returnbase.CellTemplate; |
| } |
| set |
| { |
| if((value==null)||!(valueisCustomLookUpCell)) |
| { |
| thrownewArgumentException("CanonlycontainCustomLookUpCell"); |
| } |
| base.CellTemplate=value; |
| } |
| } |
|
| privateCustomLookUpCellCustomLookUpCellTemplate |
| { |
| get |
| { |
| return(CustomLookUpCell)this.CellTemplate; |
| } |
| } |
|
| publicoverridestringToString() |
| { |
| StringBuilderstringBuilder=newStringBuilder(100); |
| stringBuilder.Append("DataGridViewCustomLookUpColumn{Name="); |
| stringBuilder.Append(this.Name); |
| stringBuilder.Append(",Index="); |
| stringBuilder.Append(this.Index.ToString(CultureInfo.CurrentCulture)); |
| stringBuilder.Append("}"); |
| returnstringBuilder.ToString(); |
| } |
|
| privatestringformName; |
|
| [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] |
| [Category("Misc")] |
| [Description("Thenameoftheformwhichmustbeshow.")] |
| publicstringFormName |
| { |
| get |
| { |
| returnthis.formName; |
| } |
| set |
| { |
| this.formName=value; |
| } |
|
| } |
|
| privatestringnameSpace; |
|
| [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] |
| [Category("Misc")] |
| [Description("Thenamespacetheofformwhichmustbeshow.")] |
| publicstringNameSpace |
| { |
| get |
| { |
| returnthis.nameSpace; |
| } |
| set |
| { |
| this.nameSpace=value; |
| } |
| } |
|
| privatestringdisplayMember; |
|
| [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] |
| [Category("Misc")] |
| [Description("Thenameofthepropertywhichmustbeshowinsidethecontrol.")] |
| publicstringDisplayMember |
| { |
| get |
| { |
| returnthis.displayMember; |
| } |
| set |
| { |
| this.displayMember=value; |
| } |
|
| } |
|
| privatestringvalueMember; |
|
| [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] |
| [Category("Misc")] |
| [Description("Thenameofthepropertywhichmustbebind.")] |
| publicstringValueMember |
| { |
| get |
| { |
| returnthis.valueMember; |
| } |
| set |
| { |
| this.valueMember=value; |
| } |
|
| } |
| |
|
| publicoverrideobjectClone() |
| { |
| CustomLookUpColumncustomLookUpColumn=base.Clone()asCustomLookUpColumn; |
| customLookUpColumn.FormName=formName; |
| customLookUpColumn.NameSpace=nameSpace; |
| customLookUpColumn.DisplayMember=displayMember; |
| customLookUpColumn.ValueMember=valueMember; |
| returncustomLookUpColumn; |
| |
| } |
| } |
|
| [ToolboxItem(true)] |
| [ToolboxBitmap(typeof(CustomLookUpConrol),"CustomLookUpConrol.bmp")] |
| publicclassCustomLookUpConrol:LookUp,IDataGridViewEditingControl |
| { |
| publicCustomLookUpConrol() |
| { |
| this.LookUPTextBox.TextChanged+=newEventHandler(LookUPTextBox_TextChanged); |
| this.LookUPButton.Click+=newEventHandler(LookUPButton_Click); |
| } |
|
| voidLookUPTextBox_TextChanged(objectsender,EventArgse) |
| { |
| //LettheDataGridViewknowaboutthevaluechange. |
| this.NotifyDataGridViewOfValueChange(); |
| } |
|
| voidLookUPButton_Click(objectsender,EventArgse) |
| { |
| //CustomLookUpColumn.ButtonClickHandler(sender,e,this.LookUPTextBox); |
|
| Formform=(Form)Assembly.GetExecutingAssembly().CreateInstance((senderasButton).FormName.ToString()); |
| if(form.ShowDialog()==DialogResult.OK) |
| { |
| PropertyInfodisplayMember=form.Tag.GetType().GetProperties().Single(c=>c.Name==this.LookUPTextBox.DisplayMember.ToString()); |
| PropertyInfovalueMemeber=form.Tag.GetType().GetProperties().Single(c=>c.Name==this.LookUPTextBox.ValueMember.ToString()); |
| this.LookUPTextBox.Text=displayMember.GetValue(form.Tag,null).ToString(); |
| } |
| |
| } |
|
| privatevoidInitializeComponent() |
| { |
| this.SuspendLayout(); |
| // |
| //CustomLookUpConrol |
| // |
| this.AutoScaleDimensions=newSystem.Drawing.SizeF(6F,13F); |
| this.Name="CustomLookUpConrol"; |
| this.ResumeLayout(false); |
| this.PerformLayout(); |
|
| } |
|
| privateDataGridViewdataGridView; |
| privateintrowIndex; |
| privateboolvalueChanged; |
|
| #regionIDataGridViewEditingControlMembers |
|
| publicvoidApplyCellStyleToEditingControl(DataGridViewCellStyledataGridViewCellStyle) |
| { |
| this.Font=dataGridViewCellStyle.Font; |
| this.BackColor=dataGridViewCellStyle.BackColor; |
| this.ForeColor=dataGridViewCellStyle.ForeColor; |
| } |
|
| publicDataGridViewEditingControlDataGridView |
| { |
| get |
| { |
| returnthis.dataGridView; |
| } |
| set |
| { |
| this.dataGridView=value; |
| } |
| } |
|
| publicobjectEditingControlFormattedValue |
| { |
| get |
| { |
| returnthis.Text; |
| } |
| set |
| { |
| this.Text=value.ToString(); |
| } |
| } |
|
| publicintEditingControlRowIndex |
| { |
| get |
| { |
| returnthis.rowIndex; |
| } |
| set |
| { |
| this.rowIndex=value; |
| } |
| } |
|
| publicboolEditingControlValueChanged |
| { |
| get |
| { |
| returnthis.valueChanged; |
| } |
| set |
| { |
| this.valueChanged=value; |
| } |
| } |
|
| publicboolEditingControlWantsInputKey(KeyskeyData,booldataGridViewWantsInputKey) |
| { |
| returntrue; |
| } |
|
| publicCursorEditingPanelCursor |
| { |
| get |
| { |
| returnCursors.Default; |
| } |
| } |
|
| publicobjectGetEditingControlFormattedValue(DataGridViewDataErrorContextscontext) |
| { |
| returnthis.EditingControlFormattedValue; |
| } |
|
| publicvoidPrepareEditingControlForEdit(boolselectAll) |
| { |
| System.Windows.Forms.TextBoxtextBox=this.LookUPTextBox; |
| if(textBox!=null) |
| { |
| if(selectAll) |
| textBox.SelectAll(); |
| else |
| textBox.SelectionStart=textBox.Text.Length; |
| } |
| } |
|
| publicboolRepositionEditingControlOnValueChange |
| { |
| get |
| { |
| returnfalse; |
| } |
| } |
|
| #endregion |
|
| privatevoidNotifyDataGridViewOfValueChange() |
| { |
| if(!this.valueChanged) |
| { |
| this.valueChanged=true; |
| this.dataGridView.NotifyCurrentCellDirty(true); |
| } |
| } |
|
| protectedoverridevoidOnKeyPress(KeyPressEventArgse) |
| { |
| base.OnKeyPress(e); |
| //LettheDataGridViewknowaboutthevaluechange. |
| this.NotifyDataGridViewOfValueChange(); |
| } |
| } |