|
| 1 | +using Syncfusion.Windows.Forms.Grid; |
| 2 | +using System; |
| 3 | +using System.Collections.Generic; |
| 4 | +using System.ComponentModel; |
| 5 | +using System.Data; |
| 6 | +using System.Drawing; |
| 7 | +using System.Linq; |
| 8 | +using System.Text; |
| 9 | +using System.Threading.Tasks; |
| 10 | +using System.Windows.Forms; |
| 11 | + |
| 12 | +namespace DataGrid |
| 13 | +{ |
| 14 | + public partial class Form2 : Form |
| 15 | + { |
| 16 | + public Form2() |
| 17 | + { |
| 18 | + InitializeComponent(); |
| 19 | + this.gridControl1.RowCount = 15; |
| 20 | + this.gridControl1.ColCount = 6; |
| 21 | + gridControl1.RowCount = 100; |
| 22 | + gridControl1.ColCount = 11; |
| 23 | + this.gridControl1.DefaultRowHeight = 30; |
| 24 | + CreateTable(); |
| 25 | + for (int i = 1; i <= this.gridControl1.RowCount; i++) |
| 26 | + { |
| 27 | + for (int j = 1; j <= this.gridControl1.ColCount; j++) |
| 28 | + { |
| 29 | + this.gridControl1[i, j].CellValue = dt.Rows[i - 1][j - 1]; |
| 30 | + } |
| 31 | + } |
| 32 | + for (int i = 1; i <= gridControl1.RowCount; i++) |
| 33 | + { |
| 34 | + gridControl1[i, 3].CellType = GridCellTypeName.PushButton; |
| 35 | + } |
| 36 | + for (int i = 1; i <= gridControl1.RowCount; i++) |
| 37 | + { |
| 38 | + gridControl1[i, 7].CellType = GridCellTypeName.PushButton; |
| 39 | + } |
| 40 | + //Event triggering |
| 41 | + this.gridControl1.DrawCellButton += GridControl1_DrawCellButton; |
| 42 | + } |
| 43 | + |
| 44 | + private void GridControl1_DrawCellButton(object sender, GridDrawCellButtonEventArgs e) |
| 45 | + { |
| 46 | + if (e.Style.CellType == GridCellTypeName.PushButton) |
| 47 | + { |
| 48 | + Bitmap bitmap = new Bitmap(30, 20); |
| 49 | + Rectangle rect = e.Button.Bounds; |
| 50 | + if (e.ColIndex == 3) |
| 51 | + { |
| 52 | + bitmap = new Bitmap(SystemIcons.Error.ToBitmap(), new Size(30, 25)); |
| 53 | + } |
| 54 | + if (e.ColIndex == 7) |
| 55 | + { |
| 56 | + bitmap = new Bitmap(SystemIcons.Exclamation.ToBitmap(), new Size(20, 20)); |
| 57 | + } |
| 58 | + e.Graphics.DrawImage(bitmap, rect.X + 30, rect.Y, bitmap.Width, bitmap.Height); |
| 59 | + e.Cancel = true; |
| 60 | + } |
| 61 | + } |
| 62 | + #region "Create DataTable" |
| 63 | + string[] name1 = new string[] { "John", "Peter", "Smith", "Jay", "Krish", "Mike" }; |
| 64 | + string[] country = new string[] { "UK", "USA", "Pune", "India", "China", "England" }; |
| 65 | + string[] city = new string[] { "Graz", "Resende", "Bruxelles", "Aires", "Rio de janeiro", "Campinas" }; |
| 66 | + string[] scountry = new string[] { "Brazil", "Belgium", "Austria", "Argentina", "France", "Beiging" }; |
| 67 | + DataTable dt = new DataTable(); |
| 68 | + Random r = new Random(); |
| 69 | + int col = 0; |
| 70 | + private DataTable CreateTable() |
| 71 | + { |
| 72 | + if (col == 0) |
| 73 | + { |
| 74 | + dt.Columns.Add("Name"); |
| 75 | + dt.Columns.Add("Id"); |
| 76 | + dt.Columns.Add("Date"); |
| 77 | + dt.Columns.Add("Country"); |
| 78 | + dt.Columns.Add("Ship City"); |
| 79 | + dt.Columns.Add("Ship Country"); |
| 80 | + dt.Columns.Add("Freight"); |
| 81 | + dt.Columns.Add("Postal code"); |
| 82 | + dt.Columns.Add("Salary"); |
| 83 | + dt.Columns.Add("PF"); |
| 84 | + dt.Columns.Add("EMI"); |
| 85 | + } |
| 86 | + for (int l = 0; l < dt.Columns.Count; l++) |
| 87 | + |
| 88 | + for (int i = 0; i < this.gridControl1.RowCount; i++) |
| 89 | + { |
| 90 | + DataRow dr = dt.NewRow(); |
| 91 | + for (int j = 0; j < this.gridControl1.ColCount; j++) |
| 92 | + { |
| 93 | + dr[0] = name1[r.Next(0, 5)]; |
| 94 | + dr[1] = "E" + r.Next(30); |
| 95 | + dr[2] = new DateTime(2012, 5, 23); |
| 96 | + dr[3] = country[r.Next(0, 5)]; |
| 97 | + dr[4] = city[r.Next(0, 5)]; |
| 98 | + dr[5] = scountry[r.Next(0, 5)]; |
| 99 | + dr[6] = r.Next(1000, 2000); |
| 100 | + dr[7] = r.Next(10 + (r.Next(600000, 600100))); |
| 101 | + dr[8] = r.Next(14000, 20000); |
| 102 | + dr[9] = r.Next(r.Next(2000, 4000)); |
| 103 | + dr[10] = r.Next(300, 1000); |
| 104 | + } |
| 105 | + dt.Rows.Add(dr); |
| 106 | + } |
| 107 | + return dt; |
| 108 | + } |
| 109 | + #endregion |
| 110 | + } |
| 111 | +} |
| 112 | + |
0 commit comments