|
| 1 | +#region Copyright Syncfusion Inc. 2001 - 2005 |
| 2 | +// |
| 3 | +// Copyright Syncfusion Inc. 2001 - 2005. All rights reserved. |
| 4 | +// |
| 5 | +// Use of this code is subject to the terms of our license. |
| 6 | +// A copy of the current license can be obtained at any time by e-mailing |
| 7 | +// licensing@syncfusion.com. Any infringement will be prosecuted under |
| 8 | +// applicable laws. |
| 9 | +// |
| 10 | +#endregion |
| 11 | + |
| 12 | +using System; |
| 13 | +using System.Drawing; |
| 14 | +using System.Collections; |
| 15 | +using System.Collections.Specialized; |
| 16 | +using System.ComponentModel; |
| 17 | +using System.Windows.Forms; |
| 18 | +using System.Data; |
| 19 | +using Syncfusion.Windows.Forms.Grid; |
| 20 | +using Syncfusion.ComponentModel; |
| 21 | + |
| 22 | +namespace GridPopulationSample |
| 23 | +{ |
| 24 | + /// <summary> |
| 25 | + /// Summary description for Form1. |
| 26 | + /// </summary> |
| 27 | + public class Form1 : System.Windows.Forms.Form |
| 28 | + { |
| 29 | + private Syncfusion.Windows.Forms.Grid.GridControl gridControl1; |
| 30 | + |
| 31 | + private DataTable dt; |
| 32 | + private int numArrayRows; |
| 33 | + private int numArrayCols; |
| 34 | + private System.Windows.Forms.Button button1; |
| 35 | + /// <summary> |
| 36 | + /// Required designer variable. |
| 37 | + /// </summary> |
| 38 | + private System.ComponentModel.Container components = null; |
| 39 | + |
| 40 | + public Form1() |
| 41 | + { |
| 42 | + // |
| 43 | + // Required for Windows Form Designer support |
| 44 | + // |
| 45 | + InitializeComponent(); |
| 46 | + |
| 47 | + this.SetUpData(); |
| 48 | + |
| 49 | + } |
| 50 | + |
| 51 | + /// <summary> |
| 52 | + /// Clean up any resources being used. |
| 53 | + /// </summary> |
| 54 | + protected override void Dispose( bool disposing ) |
| 55 | + { |
| 56 | + if( disposing ) |
| 57 | + { |
| 58 | + if (components != null) |
| 59 | + { |
| 60 | + components.Dispose(); |
| 61 | + } |
| 62 | + } |
| 63 | + base.Dispose( disposing ); |
| 64 | + } |
| 65 | + |
| 66 | + #region Windows Form Designer generated code |
| 67 | + /// <summary> |
| 68 | + /// Required method for Designer support - do not modify |
| 69 | + /// the contents of this method with the code editor. |
| 70 | + /// </summary> |
| 71 | + private void InitializeComponent() |
| 72 | + { |
| 73 | + this.gridControl1 = new Syncfusion.Windows.Forms.Grid.GridControl(); |
| 74 | + this.button1 = new System.Windows.Forms.Button(); |
| 75 | + ((System.ComponentModel.ISupportInitialize)(this.gridControl1)).BeginInit(); |
| 76 | + this.SuspendLayout(); |
| 77 | + // |
| 78 | + // gridControl1 |
| 79 | + // |
| 80 | + this.gridControl1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) |
| 81 | + | System.Windows.Forms.AnchorStyles.Left) |
| 82 | + | System.Windows.Forms.AnchorStyles.Right))); |
| 83 | + this.gridControl1.DefaultColWidth = 75; |
| 84 | + this.gridControl1.DefaultGridBorderStyle = Syncfusion.Windows.Forms.Grid.GridBorderStyle.Solid; |
| 85 | + this.gridControl1.ForeColor = System.Drawing.SystemColors.ControlText; |
| 86 | + this.gridControl1.Location = new System.Drawing.Point(8, 8); |
| 87 | + this.gridControl1.Name = "gridControl1"; |
| 88 | + this.gridControl1.RightToLeft = System.Windows.Forms.RightToLeft.No; |
| 89 | + this.gridControl1.RowCount = 1000; |
| 90 | + this.gridControl1.RowHeightEntries.AddRange(new Syncfusion.Windows.Forms.Grid.GridRowHeight[] { |
| 91 | + new Syncfusion.Windows.Forms.Grid.GridRowHeight(0, 24)}); |
| 92 | + this.gridControl1.Size = new System.Drawing.Size(808, 240); |
| 93 | + this.gridControl1.SmartSizeBox = false; |
| 94 | + this.gridControl1.TabIndex = 0; |
| 95 | + this.gridControl1.ThemesEnabled = true; |
| 96 | + // |
| 97 | + // button1 |
| 98 | + // |
| 99 | + this.button1.Anchor = System.Windows.Forms.AnchorStyles.Bottom; |
| 100 | + this.button1.Location = new System.Drawing.Point(328, 264); |
| 101 | + this.button1.Name = "button1"; |
| 102 | + this.button1.Size = new System.Drawing.Size(128, 23); |
| 103 | + this.button1.TabIndex = 1; |
| 104 | + this.button1.Text = "Wire/Unwire FilterBar"; |
| 105 | + this.button1.Click += new System.EventHandler(this.button1_Click); |
| 106 | + // |
| 107 | + // Form1 |
| 108 | + // |
| 109 | + this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); |
| 110 | + this.ClientSize = new System.Drawing.Size(824, 294); |
| 111 | + this.Controls.Add(this.button1); |
| 112 | + this.Controls.Add(this.gridControl1); |
| 113 | + this.Name = "Form1"; |
| 114 | + this.Text = "Form1"; |
| 115 | + this.Load += new System.EventHandler(this.Form1_Load); |
| 116 | + ((System.ComponentModel.ISupportInitialize)(this.gridControl1)).EndInit(); |
| 117 | + this.ResumeLayout(false); |
| 118 | + |
| 119 | + } |
| 120 | + #endregion |
| 121 | + |
| 122 | + /// <summary> |
| 123 | + /// The main entry point for the application. |
| 124 | + /// </summary> |
| 125 | + [STAThread] |
| 126 | + public static void Main() |
| 127 | + { |
| 128 | + Application.Run(new Form1()); |
| 129 | + } |
| 130 | + |
| 131 | + |
| 132 | + private void SetUpData() |
| 133 | + { |
| 134 | + this.Cursor = Cursors.WaitCursor; |
| 135 | + this.numArrayCols = 10; |
| 136 | + this.numArrayRows = 10; |
| 137 | + |
| 138 | + this.dt = new DataTable(); |
| 139 | + for(int i =0;i<this.numArrayCols;i++) |
| 140 | + { |
| 141 | + DataColumn col = new DataColumn(string.Format("Column {0}",Convert.ToChar(65+i))); |
| 142 | + dt.Columns.Add(col); |
| 143 | + } |
| 144 | + |
| 145 | + Random r = new Random(); |
| 146 | + for (int i = 0; i < this.numArrayRows; ++i) |
| 147 | + { |
| 148 | + DataRow row= dt.NewRow(); |
| 149 | + for(int j = 0; j < this.numArrayCols; ++j) |
| 150 | + { |
| 151 | + int ch = r.Next(87); |
| 152 | + ch = ch>65?ch:65; |
| 153 | + row[j] = (Convert.ToChar(ch)); |
| 154 | + } |
| 155 | + this.dt.Rows.Add(row); |
| 156 | + } |
| 157 | + this.Cursor = Cursors.Arrow; |
| 158 | + } |
| 159 | + |
| 160 | + |
| 161 | + |
| 162 | + GridControlFilterBar filterBar; |
| 163 | + |
| 164 | + private void Form1_Load(object sender, System.EventArgs e) |
| 165 | + { |
| 166 | + filterBar = new GridControlFilterBar(); |
| 167 | + filterBar.WireGrid(this.gridControl1,this.dt); |
| 168 | + |
| 169 | + this.gridControl1.ResetVolatileData(); |
| 170 | + |
| 171 | + this.gridControl1.QueryCellInfo += new GridQueryCellInfoEventHandler(QueryCellInfoHandler); |
| 172 | + this.gridControl1.QueryColCount += new GridRowColCountEventHandler(GridQueryColCount); |
| 173 | + this.gridControl1.QueryRowCount += new GridRowColCountEventHandler(GridQueryRowCount); |
| 174 | + this.gridControl1.SaveCellInfo += new GridSaveCellInfoEventHandler(SaveCellInfoHandler); |
| 175 | + |
| 176 | + for(int i = 1;i<=10;i++) |
| 177 | + this.gridControl1[0,i].Text = string.Format("Column {0}",Convert.ToChar(64+i)); |
| 178 | + |
| 179 | + this.gridControl1.Refresh(); |
| 180 | + } |
| 181 | + |
| 182 | + |
| 183 | + #region Virtual Mode |
| 184 | + |
| 185 | + private void QueryCellInfoHandler(object sender, GridQueryCellInfoEventArgs e) |
| 186 | + { |
| 187 | + int filterCheck = 0; |
| 188 | + if(filterBar.IsWired) |
| 189 | + filterCheck = 1; |
| 190 | + if(e.ColIndex > 0 && e.RowIndex > 0 && e.RowIndex != filterCheck) |
| 191 | + { |
| 192 | + e.Style.CellValue = this.dt.DefaultView[e.RowIndex-(1+filterCheck)][e.ColIndex - 1]; |
| 193 | + e.Handled = true; |
| 194 | + } |
| 195 | + else |
| 196 | + if(e.ColIndex == 0 && e.RowIndex>0) |
| 197 | + { |
| 198 | + e.Style.Text = " "; |
| 199 | + } |
| 200 | + } |
| 201 | + private void SaveCellInfoHandler(object sender, GridSaveCellInfoEventArgs e) |
| 202 | + { |
| 203 | + if(e.ColIndex > 0 && e.RowIndex > 1) |
| 204 | + { |
| 205 | + this.dt.DefaultView[e.RowIndex-2][e.ColIndex - 1] = e.Style.CellValue; |
| 206 | + e.Handled = true; |
| 207 | + } |
| 208 | + } |
| 209 | + private void GridQueryColCount(object sender, GridRowColCountEventArgs e) |
| 210 | + { |
| 211 | + e.Count = this.numArrayCols; |
| 212 | + e.Handled = true; |
| 213 | + } |
| 214 | + |
| 215 | + private void GridQueryRowCount(object sender, GridRowColCountEventArgs e) |
| 216 | + { |
| 217 | + e.Count = filterBar.RowCount; |
| 218 | + e.Handled = true; |
| 219 | + } |
| 220 | + |
| 221 | + #endregion |
| 222 | + |
| 223 | + private void button1_Click(object sender, System.EventArgs e) |
| 224 | + { |
| 225 | + if(this.filterBar.IsWired) |
| 226 | + this.filterBar.UnwireGrid(); |
| 227 | + else |
| 228 | + this.filterBar.WireGrid(this.gridControl1,this.dt); |
| 229 | + |
| 230 | + } |
| 231 | + |
| 232 | + } |
| 233 | + |
| 234 | +} |
0 commit comments