DataSourceArray.cs
上传用户:lxycoco
上传日期:2022-07-21
资源大小:38457k
文件大小:2k
源码类别:

C#编程

开发平台:

Others

  1. using System;
  2. using System.Windows.Forms;
  3. using System.Data;
  4. using System.Data.SqlClient;
  5. /// <summary>
  6. /// This class provides an example of creating and using a data grid.
  7. /// </summary>
  8. public class DatasourceArray : System.Windows.Forms.Form
  9. {
  10. private System.Windows.Forms.Button retrieveButton ;
  11. private System.Windows.Forms.DataGrid dataGrid ;
  12. /// <summary>
  13. /// Construct the window.
  14. /// </summary>
  15. /// <remarks>
  16. /// This method constructs the window by creating both the data grid and the button.
  17. /// </remarks>
  18. public DatasourceArray ( )
  19. {
  20. this.AutoScaleBaseSize = new System.Drawing.Size (5, 13);
  21. this.ClientSize = new System.Drawing.Size (464, 253);
  22. this.Text = "02_DatasourceArray" ;
  23. this.dataGrid = new System.Windows.Forms.DataGrid ();
  24. dataGrid.BeginInit ();
  25. dataGrid.Location = new System.Drawing.Point (8, 8);
  26. dataGrid.Size = new System.Drawing.Size (448, 208);
  27. dataGrid.TabIndex = 0;
  28. dataGrid.Anchor = AnchorStyles.Bottom | AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right ;
  29. this.Controls.Add (this.dataGrid);
  30. dataGrid.EndInit ();
  31. this.retrieveButton = new System.Windows.Forms.Button ();
  32. retrieveButton.Location = new System.Drawing.Point (384, 224);
  33. retrieveButton.Size = new System.Drawing.Size (75, 23);
  34. retrieveButton.TabIndex = 1;
  35. retrieveButton.Anchor = AnchorStyles.Bottom | AnchorStyles.Right ;
  36. retrieveButton.Text = "Retrieve";
  37. retrieveButton.Click += new System.EventHandler (this.retrieveButton_Click);
  38. this.Controls.Add (this.retrieveButton);
  39. }
  40. /// <summary>
  41. /// Retrieve the data
  42. /// </summary>
  43. /// <param name="sender"> </param>
  44. /// <param name="e"> </param>
  45. protected void retrieveButton_Click (object sender, System.EventArgs e)
  46. {
  47. retrieveButton.Enabled = false ;
  48. Item[] items = new Item[] { new Item ( "One" ) , 
  49.  new Item ( "Two" ) , 
  50.  new Item ( "Three" ) } ;
  51. dataGrid.SetDataBinding ( items , null ) ;
  52. }
  53. protected class Item
  54. {
  55. public Item ( string text )
  56. {
  57. m_text = text ;
  58. }
  59. public string Text
  60. {
  61. get { return m_text ; }
  62. }
  63. private string m_text ;
  64. }
  65. /// <summary>
  66. /// Display the application window
  67. /// </summary>
  68. static void Main() 
  69. {
  70. Application.Run(new DatasourceArray());
  71. }
  72. }