Custom Views Demo

For non-nested data tables, you can use Essential Grid's Grid Grouping Control to quickly provide custom views of your data. You can filter, group, sort, and summarize data with summary rows.

In this picture, you will see a Customers table, which is filtered by country, showing the cities that are available for that country. It also shows options in the Sorting menu.

CustomViews

The code to invoke the GridColumnDescriptorCollection window is given below.

    		_ShowGridColumnsDialog(this.groupingGrid1.Engine.TableDescriptor, "Columns", null, typeof(GridColumnDescriptorCollection));   

Similarly, other property windows are invoked through the same code but with the exact property as the argument.

This is passed into the following method:

    		internal DialogResult _ShowGridColumnsDialog(object instance, string propertyName, IServiceProvider provider, Type type)
    		{
    			GroupingCollectionEditor ce = new GroupingCollectionEditor(type);
    			Syncfusion.ComponentModel.WindowsFormsEditorServiceContainer esc = new Syncfusion.ComponentModel.WindowsFormsEditorServiceContainer(provider);
    			PropertyDescriptor pd = TypeDescriptor.GetProperties(instance)[propertyName];
    			Syncfusion.ComponentModel.TypeDescriptorContext tdc = new Syncfusion.ComponentModel.TypeDescriptorContext(instance, pd);
    			tdc.ServiceProvider = esc;

    			ce.EditValue(tdc, esc, pd.GetValue(instance));

    			return esc.DialogResult;
    		}  

Here is the code to reset to the default properties:

    		this.groupingGrid1.ResetTableDescriptor();   

Here is the code to reset the column sets:

    		this.groupingGrid1.Engine.TableDescriptor.ResetColumnSets();  

Here is the code to reset the column order:

    		this.groupingGrid1.Engine.TableDescriptor.VisibleColumns.Reset();  

Here is the code to browse the table:

    		fprivate void menuItemBrowseTable_Click(object sender, System.EventArgs e)
    		{
    			SelectTableForm f = new SelectTableForm();
    			f.Table = this.groupingGrid1.Engine.DataMember;
    			if (fileName != "")
    			{
    				f.FileName = fileName;
    				f.Table = this.groupingGrid1.Engine.DataMember;
    			}
    			if (f.ShowDialog() == DialogResult.OK && f.Table != "")
    			{
    				fileName = f.FileName;
    				OleDbDataAdapter dataAdapter = null;
    				DataSet _dataSet = null;
    				string tableName = f.Table;
    				try
    				{
    					// Connection object
    					if (connection == null)
    					connection = new OleDbConnection(f.ConnectionString);

    					// Create data adapter object.
    					dataAdapter = new OleDbDataAdapter("SELECT * FROM [" + tableName + "]", connection);

    					// Create a dataset object and fill it with data using the data adapter's Fill method_dataSet = new DataSet();
    					dataAdapter.Fill(_dataSet, tableName);
    					connection.Close();

    					this.groupingGrid1.CancelEdit();
    					if (f.ResetColumnChecked || f.Table != this.groupingGrid1.Engine.DataMember)
    					{
    						this.groupingGrid1.ResetTableDescriptor();
    					}
    					this.groupingGrid1.Engine.DataMember = "";
    					this.groupingGrid1.Engine.DataSource = _dataSet.Tables[tableName];
    					this.Text = tableName;
    				}
    				catch(Exception ex)
    				{
    					MessageBox.Show("Problem with DB access-\n\n   connection: "
    						+ f.ConnectionString + "\n\n" + ex.ToString());
    					return;
    				}
    			}  

Here is the code to add a summary row with RecordCount:

    		GridSummaryRowDescriptor sd = null;//Creating a new SummaryRowDescriptor 

    		// Checking if such rows are already present. If not, creating a new one.
    		if (this.groupingGrid1.Engine.TableDescriptor.SummaryRows.Contains("RecordCount"))
    			sd = this.groupingGrid1.Engine.TableDescriptor.SummaryRows["RecordCount"];
    		else
    			this.groupingGrid1.Engine.TableDescriptor.SummaryRows.Add(sd = new GridSummaryRowDescriptor("RecordCount"));
    			sd.Title = "Record Count";
    			GridSummaryColumnDescriptor column = new GridSummaryColumnDescriptor();
    			column.SummaryType = SummaryType.Count;
    			column.Style = GridSummaryStyle.FillRow;
    			column.DataMember = "(Record)";
    			column.Format = "      {Count} Records.";
    			sd.SummaryColumns.Add(column);