First, renderings
Implementation
n Code Transformation [Enter the encoded focus to leave the name].
n pulls out the selection window with DataGrid.
n background window does not lose focus
Second, development background
Seeing that the N multi-program has this kind of function, such as the drop-down data window of the PB, Delphi also has the same kind of Grid and DOTNET's Grid control does not have this feature, two words "depressed", cooperate with some of the experience in the previous article And knowledge is easy, you can make the function, in the document returns 9CBS, the digital code. I am in the heart. If you want to reprint the article, please qq: 65323574 Email: Flashelf@163.com
Third, the program realizes code analysis
Description: The SystemShell and NOACTForm class use in this article in the previous article "DOTNET desktop programming program. Down-down box. Similar Word color drop-down box" is not repeated here.
Address: http://blog.9cbs.net/flashelf/archive/2005/01/30/273954.aspx
3.1 DataGridvnTextColumnStyle Class
The most basic class of this article [has a code, name conversion function]
using System; using System.Collections; using System.ComponentModel; using System.Drawing; using System.Windows.Forms; using System.Data; using System.Diagnostics; namespace MagicLink.FlashElf.Windows.Controls.WinDataGrid.ColumnStyle {// /
TEXTBOX_KEYPRESS "); iSEDIT = true;} ///
try {isCommit = true; // get the current cell data GetColumnValueAtRow object ActData = GetColumnValueAtRow (dataSource, rowNum); // current data in the TextBox string TextBoxText = TextBox.Text; bool isAbort = false;! if (DataCommit = null {Try {// Trigger Event [This makes it easy to control the user's input when using this class] // Event can use exception to stop submitting the DataGrid and pop up the prompt datacommit (actdata, textboxtext, ref isabort);} catch (Exception EX) ) {Throw ex;}} f (isabort) {Abort (rownum); Return False; _dv.sort = _valuemember; int index = 0; try {if (textBox.text! = "&& textbox.text! = nulltext) {Object odate = textbox.text; // Judgment data in DataView There is no return -1 index = _dv.find (odate);} else {// is set to DBNULL BASETCOLUMNVALUEATROW (DataSource, Rownum, System.dbnull.Value);
}}}} Catch (formatexception fEX) {fEX.getHashCode (); // Input is not expected type index = -1;} catch (exception ex) {// Other exception through ex;} if (index <0) {/ / If you are not a expected data throw new applicationException ("Enter incorrect data!");}; Try {return base.commit (datasource, rownum);} catch (exception ex) {throw ex;}} finaryly {/ / Restore switching variable ISCommit = false; ISEDIT = false;}} /// _imageList.ImageStream "))); this._imageList.TransparentColor = System.Drawing.Color.Transparent;} public DataGridVNButtonColumnStyle (): base () {InitializeComponent (); base.Disposed = new EventHandler (DataGridVNButtonColumnStyle_Disposed); _button.Dock = DockStyle.Right; _button.Size = new Size (16,16); base.TextBox.Controls.Add (_button); _button.GotFocus = new EventHandler (_button_GotFocus); _button.Visible = true; // // TODO: in Add constructor logic ///} /// Realize drop-down DataGrid using System; using System.Collections; using System.ComponentModel; using System.Drawing; using System.Windows.Forms; using System.Data; using System.Diagnostics; namespace MagicLink.FlashElf.Windows.Controls.WinDataGrid.ColumnStyle {// / protected override void Edit (CurrencyManager source, int rowNum, Rectangle bounds, bool readOnly, string instantText, bool cellIsVisible) {_mc = source; _Rownum = rowNum; base.Edit (source, rowNum, bounds, readOnly, instantText, cellIsVisible);} /// /// The mousemove of the drop-down window captures the mouse so you can get /// summary> /// param> /// param> private void Gf_MouseMove (object sender, MouseEventArgs e) {DataGrid Grid = _gf.dataGrid1; System.Windows.Forms.DataGrid.HitTestInfo hti; // HitTestInfo achieved by the object coordinate hti = Grid.HitTest (eX, eY); // if The position of the mouse is on the cell or row head IF (hti.type == system.windows.forms.dataGrid.hittesttype.cell || hti.type == system.windows.Forms.DataGrid.hittesttype.rowheader) {int Index = hti.row; if (index == - 1) index = 0; // Not only to how to clear the multi-selection of DataGrid this written for this for (int i = 0; i _GF.top) {system.windows.Forms.DataGrid.hittestinfo hti; hti = _gf.dataGrid1.hittest (ex, EY); // Under the row of line int index = hti.row; // If there is no Way to handle if (index == - 1) index = 0; object odate = _dv [index] [base.valuemember]; Object Olddate = base.getColumnValueatrow (_MC, _ROWNUM); // If the drop-down window Select the data line selected by the drop-down window And the original data different if (! Olddate.equals (odate)) {// Sets the current cell data setColumnValueatrow (_MC, _ROWNUM, ODATE); columnStartedEditing (base.text = Odate.toString ();}} // Hide drop-down window _gf.hide ();} /// And the general DataGridColumnStyle check private void Form1_Load (object sender, System.EventArgs e) {// prepare the DataGrid _dv.Table = GetMainTable (); // prepare drop down window data DataTable SexDt = GetShowGridTable (); DataGridTableStyle gts; gts = new DataGridTableStyle () ; DataGridVMShowGridColumnStyle Glc = new DataGridVMShowGridColumnStyle (); gts.MappingName = _dv.Table.TableName; Glc.HeaderText = "sex"; Glc.MappingName = "sex"; Glc.DataSource = SexDt; Glc.DisplayMember = "Txt"; Glc .ValueMember = "Id"; gts.GridColumnStyles.Add (Glc); dataGrid1.TableStyles.Add (gts); // add a general column DataGridColumnStyle dgcolStyle; dgcolStyle = new DataGridTextBoxColumn (); dgcolStyle.MappingName = "id"; DGCOLStyle.Headertext = "Number"; G ts.GridColumnStyles.Add (dgcolStyle); Glc.DataCommit = new DataGridVNTextColumnStyle.DelegateCommit (Glc_DataCommit); dataGrid1.DataSource = _dv;} private void Glc_DataCommit (object ActData, string TextBoxText, ref bool Abort) {// If that data does not meet Requires Abort = True can be console.writeline ("1 ::: {0}, {1}, {2}", actdata, textboxtext, abort); "); Dt.columns.add (" id ", typeof (int)); dt.columns.add (" Birthday ", TypeOf (DateTime)); DT.Columns.Add (" SEX ", TypeOf (int)); dt.Rows.add (new object [] {1, datetime.now, 1}); return dt;} Private DataTable getShowgridTable () {dataable sexdt = new data ("sextable"); sexdt.columns.add ("id", typeof (int)); sexdt.columns.add ("txt", typeof (string); sexdt .Rows.add (new object [] {1, "male"}); sexdt.rows.add (new object [] {2, "female"}); return sexdt;}