DataViewRowState 枚举

来源:互联网 发布:淘宝首页设计素材 编辑:程序博客网 时间:2024/04/30 09:58

DataViewRowState

 

 

名称

 

Added

一个新行。  <!-- /* Font Definitions */ @font-face{font-family:新細明體;panose-1:2 2 3 0 0 0 0 0 0 0;mso-font-alt:PMingLiU;mso-font-charset:136;mso-generic-font-family:roman;mso-font-pitch:variable;mso-font-signature:3 137232384 22 0 1048577 0;}@font-face{font-family:Verdana;panose-1:2 11 6 4 3 5 4 4 2 4;mso-font-charset:0;mso-generic-font-family:swiss;mso-font-pitch:variable;mso-font-signature:536871559 0 0 0 415 0;}@font-face{font-family:"/@新細明體";panose-1:2 2 3 0 0 0 0 0 0 0;mso-font-charset:136;mso-generic-font-family:roman;mso-font-pitch:variable;mso-font-signature:3 137232384 22 0 1048577 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal{mso-style-parent:"";margin:0cm;margin-bottom:.0001pt;mso-pagination:none;font-size:12.0pt;font-family:"Times New Roman";mso-fareast-font-family:新細明體;mso-font-kerning:1.0pt;} /* Page Definitions */ @page{mso-page-border-surround-header:no;mso-page-border-surround-footer:no;}@page Section1{size:612.0pt 792.0pt;margin:72.0pt 90.0pt 72.0pt 90.0pt;mso-header-margin:36.0pt;mso-footer-margin:36.0pt;mso-paper-source:0;}div.Section1{page:Section1;}-->Added

 

CurrentRows

包括未更改行、新行和已修改行的当前行。  <!-- /* Font Definitions */ @font-face{font-family:新細明體;panose-1:2 2 3 0 0 0 0 0 0 0;mso-font-alt:PMingLiU;mso-font-charset:136;mso-generic-font-family:roman;mso-font-pitch:variable;mso-font-signature:3 137232384 22 0 1048577 0;}@font-face{font-family:Verdana;panose-1:2 11 6 4 3 5 4 4 2 4;mso-font-charset:0;mso-generic-font-family:swiss;mso-font-pitch:variable;mso-font-signature:536871559 0 0 0 415 0;}@font-face{font-family:"/@新細明體";panose-1:2 2 3 0 0 0 0 0 0 0;mso-font-charset:136;mso-generic-font-family:roman;mso-font-pitch:variable;mso-font-signature:3 137232384 22 0 1048577 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal{mso-style-parent:"";margin:0cm;margin-bottom:.0001pt;mso-pagination:none;font-size:12.0pt;font-family:"Times New Roman";mso-fareast-font-family:新細明體;mso-font-kerning:1.0pt;} /* Page Definitions */ @page{mso-page-border-surround-header:no;mso-page-border-surround-footer:no;}@page Section1{size:612.0pt 792.0pt;margin:72.0pt 90.0pt 72.0pt 90.0pt;mso-header-margin:36.0pt;mso-footer-margin:36.0pt;mso-paper-source:0;}div.Section1{page:Section1;}-->Unchanged|Added|ModifiedCurred

 

Deleted

除的行。  <!-- /* Font Definitions */ @font-face{font-family:新細明體;panose-1:2 2 3 0 0 0 0 0 0 0;mso-font-alt:PMingLiU;mso-font-charset:136;mso-generic-font-family:roman;mso-font-pitch:variable;mso-font-signature:3 137232384 22 0 1048577 0;}@font-face{font-family:Verdana;panose-1:2 11 6 4 3 5 4 4 2 4;mso-font-charset:0;mso-generic-font-family:swiss;mso-font-pitch:variable;mso-font-signature:536871559 0 0 0 415 0;}@font-face{font-family:"/@新細明體";panose-1:2 2 3 0 0 0 0 0 0 0;mso-font-charset:136;mso-generic-font-family:roman;mso-font-pitch:variable;mso-font-signature:3 137232384 22 0 1048577 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal{mso-style-parent:"";margin:0cm;margin-bottom:.0001pt;mso-pagination:none;font-size:12.0pt;font-family:"Times New Roman";mso-fareast-font-family:新細明體;mso-font-kerning:1.0pt;} /* Page Definitions */ @page{mso-page-border-surround-header:no;mso-page-border-surround-footer:no;}@page Section1{size:612.0pt 792.0pt;margin:72.0pt 90.0pt 72.0pt 90.0pt;mso-header-margin:36.0pt;mso-footer-margin:36.0pt;mso-paper-source:0;}div.Section1{page:Section1;}-->Deleted

 

ModifiedCurrent

当前版本,原始数据( ModifiedOriginal )的修改版本。  <!-- /* Font Definitions */ @font-face{font-family:新細明體;panose-1:2 2 3 0 0 0 0 0 0 0;mso-font-alt:PMingLiU;mso-font-charset:136;mso-generic-font-family:roman;mso-font-pitch:variable;mso-font-signature:3 137232384 22 0 1048577 0;}@font-face{font-family:Verdana;panose-1:2 11 6 4 3 5 4 4 2 4;mso-font-charset:0;mso-generic-font-family:swiss;mso-font-pitch:variable;mso-font-signature:536871559 0 0 0 415 0;}@font-face{font-family:"/@新細明體";panose-1:2 2 3 0 0 0 0 0 0 0;mso-font-charset:136;mso-generic-font-family:roman;mso-font-pitch:variable;mso-font-signature:3 137232384 22 0 1048577 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal{mso-style-parent:"";margin:0cm;margin-bottom:.0001pt;mso-pagination:none;font-size:12.0pt;font-family:"Times New Roman";mso-fareast-font-family:新細明體;mso-font-kerning:1.0pt;} /* Page Definitions */ @page{mso-page-border-surround-header:no;mso-page-border-surround-footer:no;}@page Section1{size:612.0pt 792.0pt;margin:72.0pt 90.0pt 72.0pt 90.0pt;mso-header-margin:36.0pt;mso-footer-margin:36.0pt;mso-paper-source:0;}div.Section1{page:Section1;}-->ModifiedCurrent

 

ModifiedOriginal

原始版本(尽管它后来已被修改并以 ModifiedCurrent 形式存在)。  <!-- /* Font Definitions */ @font-face{font-family:新細明體;panose-1:2 2 3 0 0 0 0 0 0 0;mso-font-alt:PMingLiU;mso-font-charset:136;mso-generic-font-family:roman;mso-font-pitch:variable;mso-font-signature:3 137232384 22 0 1048577 0;}@font-face{font-family:Verdana;panose-1:2 11 6 4 3 5 4 4 2 4;mso-font-charset:0;mso-generic-font-family:swiss;mso-font-pitch:variable;mso-font-signature:536871559 0 0 0 415 0;}@font-face{font-family:"/@新細明體";panose-1:2 2 3 0 0 0 0 0 0 0;mso-font-charset:136;mso-generic-font-family:roman;mso-font-pitch:variable;mso-font-signature:3 137232384 22 0 1048577 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal{mso-style-parent:"";margin:0cm;margin-bottom:.0001pt;mso-pagination:none;font-size:12.0pt;font-family:"Times New Roman";mso-fareast-font-family:新細明體;mso-font-kerning:1.0pt;} /* Page Definitions */ @page{mso-page-border-surround-header:no;mso-page-border-surround-footer:no;}@page Section1{size:612.0pt 792.0pt;margin:72.0pt 90.0pt 72.0pt 90.0pt;mso-header-margin:36.0pt;mso-footer-margin:36.0pt;mso-paper-source:0;}div.Section1{page:Section1;}-->ModifiedCurrent 

 

None

无。  <!-- /* Font Definitions */ @font-face{font-family:新細明體;panose-1:2 2 3 0 0 0 0 0 0 0;mso-font-alt:PMingLiU;mso-font-charset:136;mso-generic-font-family:roman;mso-font-pitch:variable;mso-font-signature:3 137232384 22 0 1048577 0;}@font-face{font-family:Verdana;panose-1:2 11 6 4 3 5 4 4 2 4;mso-font-charset:0;mso-generic-font-family:swiss;mso-font-pitch:variable;mso-font-signature:536871559 0 0 0 415 0;}@font-face{font-family:"/@新細明體";panose-1:2 2 3 0 0 0 0 0 0 0;mso-font-charset:136;mso-generic-font-family:roman;mso-font-pitch:variable;mso-font-signature:3 137232384 22 0 1048577 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal{mso-style-parent:"";margin:0cm;margin-bottom:.0001pt;mso-pagination:none;font-size:12.0pt;font-family:"Times New Roman";mso-fareast-font-family:新細明體;mso-font-kerning:1.0pt;} /* Page Definitions */ @page{mso-page-border-surround-header:no;mso-page-border-surround-footer:no;}@page Section1{size:612.0pt 792.0pt;margin:72.0pt 90.0pt 72.0pt 90.0pt;mso-header-margin:36.0pt;mso-footer-margin:36.0pt;mso-paper-source:0;}div.Section1{page:Section1;}--> None

 

OriginalRows

包括未更改行和已 除行的原始行。  <!-- /* Font Definitions */ @font-face{font-family:新細明體;panose-1:2 2 3 0 0 0 0 0 0 0;mso-font-alt:PMingLiU;mso-font-charset:136;mso-generic-font-family:roman;mso-font-pitch:variable;mso-font-signature:3 137232384 22 0 1048577 0;}@font-face{font-family:Verdana;panose-1:2 11 6 4 3 5 4 4 2 4;mso-font-charset:0;mso-generic-font-family:swiss;mso-font-pitch:variable;mso-font-signature:536871559 0 0 0 415 0;}@font-face{font-family:"/@新細明體";panose-1:2 2 3 0 0 0 0 0 0 0;mso-font-charset:136;mso-generic-font-family:roman;mso-font-pitch:variable;mso-font-signature:3 137232384 22 0 1048577 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal{mso-style-parent:"";margin:0cm;margin-bottom:.0001pt;mso-pagination:none;font-size:12.0pt;font-family:"Times New Roman";mso-fareast-font-family:新細明體;mso-font-kerning:1.0pt;} /* Page Definitions */ @page{mso-page-border-surround-header:no;mso-page-border-surround-footer:no;}@page Section1{size:612.0pt 792.0pt;margin:72.0pt 90.0pt 72.0pt 90.0pt;mso-header-margin:36.0pt;mso-footer-margin:36.0pt;mso-paper-source:0;}div.Section1{page:Section1;}-->Unchanged|Deleted|ModifiedOriginal

 

Unchanged

未更改的行。  <!-- /* Font Definitions */ @font-face{font-family:新細明體;panose-1:2 2 3 0 0 0 0 0 0 0;mso-font-alt:PMingLiU;mso-font-charset:136;mso-generic-font-family:roman;mso-font-pitch:variable;mso-font-signature:3 137232384 22 0 1048577 0;}@font-face{font-family:Verdana;panose-1:2 11 6 4 3 5 4 4 2 4;mso-font-charset:0;mso-generic-font-family:swiss;mso-font-pitch:variable;mso-font-signature:536871559 0 0 0 415 0;}@font-face{font-family:"/@新細明體";panose-1:2 2 3 0 0 0 0 0 0 0;mso-font-charset:136;mso-generic-font-family:roman;mso-font-pitch:variable;mso-font-signature:3 137232384 22 0 1048577 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal{mso-style-parent:"";margin:0cm;margin-bottom:.0001pt;mso-pagination:none;font-size:12.0pt;font-family:"Times New Roman";mso-fareast-font-family:新細明體;mso-font-kerning:1.0pt;} /* Page Definitions */ @page{mso-page-border-surround-header:no;mso-page-border-surround-footer:no;}@page Section1{size:612.0pt 792.0pt;margin:72.0pt 90.0pt 72.0pt 90.0pt;mso-header-margin:36.0pt;mso-footer-margin:36.0pt;mso-paper-source:0;}div.Section1{page:Section1;}-->Unchanged

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int nCount;
            // Create a DataTable with one column.

            DataTable dataTable = new DataTable("dataTable");

            DataColumn dataColumn = new DataColumn("dataColumn");
            dataTable.Columns.Add(dataColumn);
            //Add ten rows
            DataRow dataRow;

            for (int i = 0; i < 10; i++)
            {

                dataRow = dataTable.NewRow();

                dataRow["dataColumn"] = "item " + i;

                dataTable.Rows.Add(dataRow);

            }
            dataTable.AcceptChanges();
            // Create a DataView with the table.
            DataView dataView = new DataView(dataTable);
            //第一次求nCount 此时cCount=10全部来自于DataTable中的10条数据

            nCount = dataView.Count;
            // Change one row's value:
            dataTable.Rows[1]["dataColumn"] = "Hello";
            // Add one row:
            dataRow = dataTable.NewRow();
            dataRow["dataColumn"] = "World";
            dataTable.Rows.Add(dataRow);
            nCount = dataView.Count; //新添了1行所以此处nCount=11
            //下面开始使用DataViewRowState的各个成员

            //首先要说明的是在使用前我们对其中一条数据进行了更改 同时新添了一条数据

            // Set the RowStateFilter to display only added and modified rows.
            dataView.RowStateFilter = DataViewRowState.Added

       | DataViewRowState.ModifiedCurrent;

            nCount = dataView.Count;
            //此处nCount=2(Added表示新添的行)

            //ModifiedCurrent 表示当前版本,原始数据(请参见 ModifiedOriginal)的修改版本

            //也就是说大前提对于修改的数据行而言的,显示的是更改后的数据

            //理解了这个后也就对于ModifiedOriginal不难理解了,他们都是对于修改的数据行而言的

            //不过这个是显示的原始数据而已。
            // Print those rows. Output = "Hello" "World";

            PrintView(dataView, "ModifiedCurrent and Added");

            // Set filter to display on originals of modified rows.

            dataView.RowStateFilter = DataViewRowState.ModifiedOriginal;

            PrintView(dataView, "ModifiedOriginal");
            // Delete three rows.

            dataTable.Rows[1].Delete();

            dataTable.Rows[2].Delete();

            dataTable.Rows[3].Delete();
            // Set the RowStateFilter to display only Added and modified rows.

            dataView.RowStateFilter = DataViewRowState.Deleted;

            //Deleted 显示的是删除的行  即3 不过此处显示的是最原始的数据

            //如上面把第2行有item 1变为Hello了,但是显示删除行信息时候还是item 1

            PrintView(dataView, "Deleted");
            //Set filter to display only current.

            dataView.RowStateFilter = DataViewRowState.CurrentRows;

            //CurrentRows就是现在DataView中包含的实实在在的数据行了

            PrintView(dataView, "Current");





            // Set filter to display only unchanged rows.

            dataView.RowStateFilter = DataViewRowState.Unchanged;

            //UnChanged 显示未更改的行 修改过1条和添加了1条应该不算的所以为7

            PrintView(dataView, "Unchanged");
            // Set filter to display only original rows.

            dataView.RowStateFilter = DataViewRowState.OriginalRows;

            //OriginalRows表示包括未更改行和已删除行的原始行 即10

            //10个中因为现在有8行其中一行为新添的7行未更改行,删除了3行(虽然3行中有1行曾更改过)提示:删除的行要么是新添的要么是原来的数据行(不管更改是否)

            PrintView(dataView, "OriginalRows");
            Console.ReadKey();
        }
        static private void PrintView(DataView dataView, string label)
        {

            Console.WriteLine("/n" + label);

            for (int i = 0; i < dataView.Count; i++)
            {

                Console.WriteLine(dataView[i]["dataColumn"]);

            }
        }
    }
}

結果

 

ModifiedCurrent and Added

Hello

World

 

ModifiedOriginal

item 1

 

Deleted

item 1

item 2

item 3

 

current

item 0

item 4

item 5

item 6

item 7

item 8

item 9

World

 

Unchanged

item 0

item 4

item 5

item 6

item 7

item 8

item 9

 

OriginalRows  

item 0

item 1

item 2

item 3

item 4

item 5

item 6

item 7

item 8

item 9

 

原创粉丝点击