熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

C#高級編程: DataGrid類的層次結構[2]

2022-06-13   來源: .NET編程 
    ——此文章摘自《C#高級編程(第版)》定價元 特價元 購買

    {
       private SystemWindowsFormsButton retrieveButton;
       private SystemWindowsFormsDataGrid dataGrid;
       public CustomDataGridTableStyle()
       {
          thisAutoScaleBaseSize = new SystemDrawingSize( );
          thisClientSize = new SystemDrawingSize( );
          thisText = _CustomDataGridTableStyle;
          thisdataGrid = new SystemWindowsFormsDataGrid();
          dataGridBeginInit();
          dataGridLocation = new SystemDrawingPoint( );
          dataGridSize = new SystemDrawingSize( );
          dataGridTabIndex = ;
          dataGridAnchor = AnchorStylesBottom | AnchorStylesTop |
                            AnchorStylesLeft | AnchorStylesRight;
          thisControlsAdd(thisdataGrid);
          dataGridEndInit();
          thisretrieveButton = new SystemWindowsFormsButton();
          retrieveButtonLocation = new SystemDrawingPoint( ); 
          retrieveButtonSize = new SystemDrawingSize( );
          retrieveButtonTabIndex = ;
          retrieveButtonAnchor = AnchorStylesBottom | AnchorStylesRight;
          retrieveButtonText = Retrieve;
          retrieveButtonClick += new
                                SystemEventHandler(thisretrieveButton_Click);
          thisControlsAdd(thisretrieveButton);
       }
       protected void retrieveButton_Click(object sender SystemEventArgs e)
       {
          retrieveButtonEnabled = false;

    這些代碼生成將要使用的DataSet接著創建了本例中要使用的DataGridTableStyle最後把DataGrid綁定到DataSet上CreateDataSet函數並不是新東西它可以從Customers表中選擇出所有的行
          DataSet ds = CreateDataSet();
          CreateStyles(dataGrid);
          dataGridSetDataBinding(ds Customers);
       }

    CreateStyles()方法比較有趣前幾行代碼創建新的DataGridTableStyle對象並且設置了它的MappingName屬性這個屬性在DataGrid顯示一個給定的DataTable時使用DataGrid可以用交替變化的顏色顯示數據行這段代碼還每隔一行定義數據行的顏色(結果如圖所示)

[]  []  []  


From:http://tw.wingwit.com/Article/program/net/201311/15058.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.