Data navigation with position

xiaoxiao2021-03-06  22

Using system.drawing; using system.collections; using system.windows.form; using system.data; using system.data.sqlclient;

A summary description of Namespace DATABIND {///

///form1. /// public class Form1: System.Windows.Forms.Form {private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.TextBox textBox2; private System.Windows.Forms.DataGrid dataGrid1; private SqlConnection con; private SqlDataAdapter ada; private DataSet ds; private System.Windows.Forms.Button btnEdit; private System.Windows.Forms.CheckBox checkBox1; private System.Windows.Forms.GroupBox groupBox1; private System.Windows.Forms.Button btnNex Private system.windows.Forms.Button Btnpre; private system.windows.Forms.Button Btndel; /// // / / The necessary designer variables. /// private system.componentmodel.container components = null;

Public Form1 () {// // Windows Form Designer Support for // InitializeComponent (); con = New SqlConnection ("Server = it003; database = pubs; uid = sa; pwd ="); con. l.en (); Ada = new sqldataadapter ("Select * from authors", con); DS = new dataset (); ada.fill (DS, "authors); this.dataGrid1.datasource = ds.tables [" authors "] .Defaultview; this.textbox1.databindings.add ("text", ds, "authors.au_id"); this.TextBox2.Databindings.add ("text", DS, "authors.city"); this.checkbox1.databindings .Add ("Checked", DS, "Authors.Contract"); // // Todo: Add any constructor code after INITIALIZECOMPONENT call //}

///

/// Clean all the resources being used. /// Protected Override Void Dispose (Bool Disposing) {if (disponents! = null) {Components.dispose ();}} Base.Dispose (DISPOSION);} #Region Windows Form The code generated by the designer /// /// designer supports the required method - do not use the code editor to modify the // / this method.

/// private void InitializeComponent () {this.textBox1 = new System.Windows.Forms.TextBox (); this.textBox2 = new System.Windows.Forms.TextBox (); this.dataGrid1 = new System. Windows.Forms.DataGrid (); this.btnEdit = new System.Windows.Forms.Button (); this.checkBox1 = new System.Windows.Forms.CheckBox (); this.groupBox1 = new System.Windows.Forms.GroupBox (); This.btnnex = new system.windows.Forms.Button (); this.btnpre = new system.windows.Forms.Button (); this.btndel = new system.windows.forms.button (); System.ComponentModel.ISupportInitialize) (this.dataGrid1)) BeginInit ();. this.groupBox1.SuspendLayout (); this.SuspendLayout (); // // textBox1 // this.textBox1.Location = new System.Drawing.Point (32, 72); this.TextBox1.name = "textBox1"; this.textBox1.tabindex = 0; this.textBox1.text = ""; this.textBox1.keydown = new system.windows.Forms.Keyeventhandler (this .TextBox1_keydown; // // textBox2 // this.textbox2.location = new sys Tem.drawing.point (32, 104); this.textBox2.name = "textbox2"; this.textbox2.size = new system.drawing.size (264, 21); this.textbox2.tabindex = 1; this.TextBox2 .Text = ""; // // dataGrid1 // this.dataGrid1.DataMember = ""; this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText; this.dataGrid1.Location = new System.Drawing.Point (32 , 168); this.DataGrid1.name = "DataGrid1"; this.dataGrid1.size = new system.drawing.size (352, 144); this.dataGrid1.tabindex = 2; this.dataGrid1.currentcellchanged =

new System.EventHandler (this.dataGrid1_CurrentCellChanged); // // btnEdit // this.btnEdit.Location = new System.Drawing.Point (192, 24); this.btnEdit.Name = "btnEdit"; this.btnEdit.Size = new system.drawing.size (72, 23); this.btnedit.tabindex = 3; this.btnedit.text = "Modification"; this.btnedit.click = new system.eventhandler (this.btnedit_click); // // checkbox1 // this.checkbox1.location = new system.drawing.point (32, 136); this.checkbox1.name = "checkbox1"; this.checkbox1.tabindex = 5; this.checkbox1.text = "?" ; // // groupbox1 // this.groupBox1.controls.add (this.btndel); this.groupBox1.controls.add (this.btnpre); this.groupBox1.controls.add (this.btnnex); this.groupBox1 .Controls.add (this.btned); this.groupbox1.location = new system.drawing.point (24, 0); this.groupBox1.name = "groupbox1"; this.groupBox1.size = new system.drawing.size (368, 64); this.groupbox1.tabindex = 6; this.groupbox1.tabstop = false; this.groupbox1.text = "control Substation "; // // btnnex // this.btnnex.location = new system.drawing.point (16, 24); this.btnnex.name =" btnnex "; this.btnnex.tabindex = 4; this.btnnex .Text = "Next"; this.btnnex.click = new system.EventHandler (this.btnnex_click); // // btnpre // this.btnpre.location = new system.drawing.point (104, 24); This.btnpre.name = "btnpre"; this.btnpre.tabindex = 5; this.btnpre.text = "Previous"; this.btnpre.click = new system.eventhandler (this.btnpre_click); ///// BTNDEL // this.btndel.location =

New system.drawing.point (272, 24); this.btndel.name = "btndel"; this.btndel.tabindex = 6; this.btndel.text = "Remove"; this.btndel.click = new system. EventHandler (this.btndel_click); // // form1 // this.autoscalebasesize = new system.drawing.size (6, 14); this.clientsize = new system.drawing.size (408, 333); this.Controls. Ad (this.groupBox1); this.Controls.add (this.Checkbox1); this.controls.add (this.dataGrid1); this.Controls.add (this.TextBox2); this.controls.add (this.TextBox1) This.Name = "Form1"; this.text = "Data Demo"; (this.DataGrid1)). Endinit (); this.groupBox1.ResumeLayout (false); this.ResumeLayout False);} #ENDREGION

///

/// The primary entry point of the application. /// [stathread] static void main () {Application.run (new form1 ());}

Private void DataGrid1_currentcellchanged (Object sender, system.eventargs e) {this.bindingcontext [ds, "authors"]. position = this.dataGrid1.currentcell.rownumber;}

private void btnEdit_Click (object sender, System.EventArgs e) {try {this.BindingContext [ds, "authors"] EndCurrentEdit ();. SqlCommandBuilder build = new SqlCommandBuilder (ada); ada.Update (ds, "authors"); } Catch (exception ex) {messagebox.show (ex.Message);}}

Private void btnnex_click (object sender, system.eventargs e) {this.bindingcontext [ds, "authors"]. position--;}

Private void btnpre_click (object sender, system.eventargs e) {this.bindingcontext [ds, "authors"]. Position ;}

Private void btndel_click (Object sender, system.eventargs e) {

DS.Tables ["authors"]. rows [this.bindingcontext [ds, "authors"]. position] .delete ();} private void textbox1_keydown (object sender, system.windows.forms.keyeventargs e) {IF (e) {i .Keycode == keys.enter) {sendkeys.send ("{tab}");}}}}

转载请注明原文地址:https://www.9cbs.com/read-79398.html

New Post(0)