WDataGrid.cs
上传用户:horngjaan
上传日期:2009-12-12
资源大小:2882k
文件大小:3k
源码类别:

Email服务器

开发平台:

C#

  1. using System;
  2. using System.Collections;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Windows.Forms;
  7. namespace LumiSoft.UI.Controls
  8. {
  9. /// <summary>
  10. /// Summary description for WDataGrid.
  11. /// </summary>
  12. public class WDataGrid : System.Windows.Forms.DataGrid
  13. {
  14. /// <summary> 
  15. /// Required designer variable.
  16. /// </summary>
  17. private System.ComponentModel.Container components = null;
  18. public WDataGrid()
  19. {
  20. // This call is required by the Windows.Forms Form Designer.
  21. InitializeComponent();
  22. // TODO: Add any initialization after the InitForm call
  23. }
  24. #region function Dispose
  25. /// <summary> 
  26. /// Clean up any resources being used.
  27. /// </summary>
  28. protected override void Dispose( bool disposing )
  29. {
  30. if( disposing )
  31. {
  32. if(components != null)
  33. {
  34. components.Dispose();
  35. }
  36. }
  37. base.Dispose( disposing );
  38. }
  39. #endregion
  40. #region Component Designer generated code
  41. /// <summary> 
  42. /// Required method for Designer support - do not modify 
  43. /// the contents of this method with the code editor.
  44. /// </summary>
  45. private void InitializeComponent()
  46. {
  47. components = new System.ComponentModel.Container();
  48. }
  49. #endregion
  50. #region override ProcessDialogKey
  51. protected override bool ProcessDialogKey(Keys keyData)
  52. {
  53. bool retVal = false;
  54. int rowIndex = this.CurrentRowIndex;
  55. if(keyData == Keys.Up && rowIndex == 0){
  56. retVal = true;
  57. }
  58. if(this.DataSource is DataView){
  59. DataView dv = (DataView)this.DataSource;
  60. if(keyData == Keys.Down && rowIndex > dv.Count-2){
  61. retVal = true;
  62. }
  63. }
  64. if(keyData == Keys.Escape){
  65. retVal = true;
  66. }
  67. if(keyData == Keys.Enter){
  68. retVal = true;
  69. }
  70. return retVal;
  71. }
  72. #endregion
  73. #region override OnDoubleClick
  74. protected override void OnDoubleClick(System.EventArgs e)
  75. {
  76. base.OnDoubleClick(e);
  77. System.Windows.Forms.DataGrid.HitTestInfo hTest = this.HitTest(this.PointToClient(Control.MousePosition));
  78. if(hTest.Row > -1){
  79. this.UnSelect(this.CurrentRowIndex);
  80. this.SelectRow(hTest.Row);
  81. }
  82. else{
  83. this.SelectRow(this.CurrentRowIndex);
  84. }
  85. }
  86. #endregion
  87. #region override OnMouseDown
  88. protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e)
  89. {
  90. base.OnMouseDown(e);
  91. System.Windows.Forms.DataGrid.HitTestInfo hTest = this.HitTest(this.PointToClient(Control.MousePosition));
  92. if(hTest.Row > -1){
  93. this.UnSelectRow(this.CurrentRowIndex);
  94. this.SelectRow(hTest.Row);
  95. }
  96. else{
  97. this.SelectRow(this.CurrentRowIndex);
  98. }
  99. }
  100. #endregion
  101. #region override OnMouseUp
  102. protected override void OnMouseUp(System.Windows.Forms.MouseEventArgs e)
  103. {
  104. base.OnMouseUp(e);
  105. System.Windows.Forms.DataGrid.HitTestInfo hTest = this.HitTest(this.PointToClient(Control.MousePosition));
  106. if(hTest.Row == -1){
  107. this.SelectRow(this.CurrentRowIndex);
  108. }
  109. }
  110. #endregion
  111. #region function SelectRow
  112. private void SelectRow(int rowIndex)
  113. {
  114. if(rowIndex > -1){
  115. this.Select(rowIndex);
  116. }
  117. }
  118. #endregion
  119. #region function UnSelectRow
  120. private void UnSelectRow(int rowIndex)
  121. {
  122. if(rowIndex > -1){
  123. this.UnSelect(rowIndex);
  124. }
  125. }
  126. #endregion
  127. }
  128. }