Advertisement
Guest User

Untitled

a guest
Jan 21st, 2019
142
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using Syncfusion.GridHelperClasses;
  2. using Syncfusion.Windows.Forms.Grid;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Data;
  6. using System.Windows.Forms;
  7. using Syncfusion.Windows.Forms;
  8.  
  9. namespace WindowsFormsApp1
  10. {
  11.     public partial class Form1 : Form
  12.     {
  13.         public Form1()
  14.         {
  15.             InitializeComponent();
  16.             GridSettings();
  17.         }
  18.  
  19.         private void GridSettings()
  20.         {
  21.            
  22.             gridGroupingControl1.DataSource = GetData();
  23.             gridGroupingControl1.GridVisualStyles = GridVisualStyles.Metro;
  24.  
  25.             gridGroupingControl1.TableDescriptor.Columns["Gender"].Appearance.AnyRecordFieldCell.CellType = GridCellTypeName.ComboBox;
  26.             gridGroupingControl1.TableDescriptor.Columns["Gender"].Appearance.AnyRecordFieldCell.DataSource = new List<DisplayItem>()
  27.             { new DisplayItem(0, "Male"), new DisplayItem(1, "Female")};
  28.             gridGroupingControl1.TableDescriptor.Columns["Gender"].Appearance.AnyRecordFieldCell.DisplayMember = nameof(DisplayItem.Text);
  29.             gridGroupingControl1.TableDescriptor.Columns["Gender"].Appearance.AnyRecordFieldCell.ValueMember = nameof(DisplayItem.ID);
  30.             gridGroupingControl1.TableDescriptor.Columns["Gender"].AllowFilter = true;
  31.  
  32.             gridGroupingControl1.TableDescriptor.Columns["Country"].Appearance.AnyRecordFieldCell.CellType = GridCellTypeName.ComboBox;
  33.             gridGroupingControl1.TableDescriptor.Columns["Country"].Appearance.AnyRecordFieldCell.DataSource = new List<DisplayItem>()
  34.             { new DisplayItem(0, "USA"), new DisplayItem(1, "UK"), new DisplayItem(2, "Canada"), new DisplayItem(3, "Australia"), new DisplayItem(4, "Other")};
  35.             gridGroupingControl1.TableDescriptor.Columns["Country"].Appearance.AnyRecordFieldCell.DisplayMember = nameof(DisplayItem.Text);
  36.             gridGroupingControl1.TableDescriptor.Columns["Country"].Appearance.AnyRecordFieldCell.ValueMember = nameof(DisplayItem.ID);
  37.             gridGroupingControl1.TableDescriptor.Columns["Country"].AllowFilter = true;
  38.  
  39.             GridExcelFilter filter = new GridExcelFilter();
  40.             filter.ColumnFilter = GridExcelFilter.GridFilterMode.DisplayText;
  41.             filter.WireGrid(gridGroupingControl1);
  42.         }
  43.  
  44.         public static DataTable GetData()
  45.         {
  46.             DataTable dt = new DataTable("MainTable");
  47.             dt.Columns.Add("Gender");
  48.             dt.Columns.Add("Country");
  49.             dt.BeginLoadData();
  50.             Random rnd = new Random();
  51.             for (int i = 0; i < 10; i++)
  52.             {
  53.                
  54.                 DataRow dr = dt.NewRow();
  55.                 dr["Gender"] = rnd.Next(0,2);
  56.                 dr["Country"] = rnd.Next(0,5);
  57.                 dt.Rows.Add(dr);
  58.             }
  59.             dt.EndLoadData();
  60.             return dt;
  61.         }
  62.  
  63.         public class DisplayItem
  64.         {
  65.             public DisplayItem(int id, string text)
  66.             {
  67.                 this.ID = id;
  68.                 this.Text = text;
  69.             }
  70.             public int ID { get; set; }
  71.             public string Text { get; set; }
  72.         }
  73.     }
  74. }
Advertisement
RAW Paste Data Copied
Advertisement