Csharp/C Sharp by API/System.Data/DataViewRowState

Материал из .Net Framework эксперт
Версия от 15:12, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

DataViewRowState.OriginalRows

<source lang="csharp"> using System; using System.Collections.Generic; using System.ruponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Configuration; using System.Data.SqlClient; // public class Form1 : Form {

   public Form1() {
       InitializeComponent();
   }
   private void getData_Click(object sender, EventArgs e) {
       using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["northwind"].ConnectionString)) {
           string select = "SELECT * FROM products";
           SqlDataAdapter da = new SqlDataAdapter(select, con);
           DataSet ds = new DataSet();
           da.Fill(ds, "Products");
           originalData.AutoGenerateColumns = true;
           originalData.DataSource = ds.Tables["Products"];
           DataView dv = new DataView(ds.Tables["Products"]);
           filteredData.AutoGenerateColumns = true;
           filteredData.DataSource = dv;
           comboBox1.SelectedIndex = 6;
           comboBox1.Enabled = true;
       }
   }
   private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) {
       DataViewRowState state;
       switch (comboBox1.Text) {
           case "Added":
               state = DataViewRowState.Added;
               break;
           case "CurrentRows":
               state = DataViewRowState.CurrentRows;
               break;
           case "Deleted":
               state = DataViewRowState.Deleted;
               break;
           case "ModifiedCurrent":
               state = DataViewRowState.ModifiedCurrent;
               break;
           case "ModifiedOriginal":
               state = DataViewRowState.ModifiedOriginal;
               break;
           case "None":
               state = DataViewRowState.None;
               break;
           case "OriginalRows":
               state = DataViewRowState.OriginalRows;
               break;
           case "Unchanged":
               state = DataViewRowState.Unchanged;
               break;
           default:
               state = DataViewRowState.OriginalRows;
               break;
       }
       try {
           ((DataView)filteredData.DataSource).RowStateFilter = state;
       } catch (Exception ex) {
           MessageBox.Show(ex.ToString());
       }
   }
   private void InitializeComponent() {
       this.originalData = new System.Windows.Forms.DataGridView();
       this.getData = new System.Windows.Forms.Button();
       this.ruboBox1 = new System.Windows.Forms.ruboBox();
       this.filteredData = new System.Windows.Forms.DataGridView();
       this.label1 = new System.Windows.Forms.Label();
       ((System.ruponentModel.ISupportInitialize)(this.originalData)).BeginInit();
       ((System.ruponentModel.ISupportInitialize)(this.filteredData)).BeginInit();
       this.SuspendLayout();
       // 
       // originalData
       // 
       this.originalData.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                   | System.Windows.Forms.AnchorStyles.Left)
                   | System.Windows.Forms.AnchorStyles.Right)));
       this.originalData.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
       this.originalData.Location = new System.Drawing.Point(12, 12);
       this.originalData.Name = "originalData";
       this.originalData.Size = new System.Drawing.Size(600, 214);
       this.originalData.TabIndex = 0;
       // 
       // getData
       // 
       this.getData.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
       this.getData.Location = new System.Drawing.Point(536, 501);
       this.getData.Name = "getData";
       this.getData.Size = new System.Drawing.Size(75, 23);
       this.getData.TabIndex = 1;
       this.getData.Text = "Get Data";
       this.getData.UseVisualStyleBackColor = true;
       this.getData.Click += new System.EventHandler(this.getData_Click);
       // 
       // comboBox1
       // 
       this.ruboBox1.DropDownStyle = System.Windows.Forms.ruboBoxStyle.DropDownList;
       this.ruboBox1.Enabled = false;
       this.ruboBox1.FormattingEnabled = true;
       this.ruboBox1.Items.AddRange(new object[] {
           "Added",
           "CurrentRows",
           "Deleted",
           "ModifiedCurrent",
           "ModifiedOriginal",
           "None",
           "OriginalRows",
           "Unchanged"});
       this.ruboBox1.Location = new System.Drawing.Point(108, 232);
       this.ruboBox1.Name = "comboBox1";
       this.ruboBox1.Size = new System.Drawing.Size(502, 21);
       this.ruboBox1.TabIndex = 2;
       this.ruboBox1.SelectedIndexChanged += new System.EventHandler(this.ruboBox1_SelectedIndexChanged);
       // 
       // filteredData
       // 
       this.filteredData.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
       this.filteredData.Location = new System.Drawing.Point(12, 259);
       this.filteredData.Name = "filteredData";
       this.filteredData.Size = new System.Drawing.Size(598, 236);
       this.filteredData.TabIndex = 3;
       // 
       // label1
       // 
       this.label1.AutoSize = true;
       this.label1.Location = new System.Drawing.Point(13, 233);
       this.label1.Name = "label1";
       this.label1.Size = new System.Drawing.Size(29, 13);
       this.label1.TabIndex = 4;
       this.label1.Text = "Filter";
       // 
       // Form1
       // 
       this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
       this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
       this.ClientSize = new System.Drawing.Size(624, 536);
       this.Controls.Add(this.label1);
       this.Controls.Add(this.filteredData);
       this.Controls.Add(this.ruboBox1);
       this.Controls.Add(this.getData);
       this.Controls.Add(this.originalData);
       ((System.ruponentModel.ISupportInitialize)(this.originalData)).EndInit();
       ((System.ruponentModel.ISupportInitialize)(this.filteredData)).EndInit();
       this.ResumeLayout(false);
       this.PerformLayout();
   }
   private System.Windows.Forms.DataGridView originalData;
   private System.Windows.Forms.Button getData;
   private System.Windows.Forms.ruboBox comboBox1;
   private System.Windows.Forms.DataGridView filteredData;
   private System.Windows.Forms.Label label1;
   [STAThread]
   static void Main() {
       Application.EnableVisualStyles();
       Application.SetCompatibleTextRenderingDefault(false);
       Application.Run(new Form1());
   }

}

 </source>