This quick start will guide you through the steps of adding C1FlexGrid and C1RulesManager controls, binding C1FlexGrid to data source, integrate C1RulesManager to the C1FlexGrid control, and applying conditional formatting on the grid data.
You can achieve the following output through the design view or completely through the code.
C# |
Copy Code
|
---|---|
this.productsTableAdapter.Fill(this.c1NWindDataSet.Products); |
To integrate RulesManager with FlexGrid, use the following code:
C# |
Copy Code
|
---|---|
rulesManager.SetC1RulesManager(flexGrid, rulesManager); |
Property | Value |
---|---|
Name | Many In Stock |
Expression | = [UnitsInStock] > 20 |
Style > BackColor | Green |
Style > ForeColor | White |
C# |
Copy Code
|
---|---|
C1FlexGrid flexGrid = new C1FlexGrid(); C1RulesManager rulesManager = new C1RulesManager(); |
C# |
Copy Code
|
---|---|
//flexGrid flexGrid.Location = new System.Drawing.Point(12, 36); flexGrid.Size = new System.Drawing.Size(544, 375); flexGrid.TabIndex = 0; // rulesManager rulesManager.Location = new System.Drawing.Point(562, 36); rulesManager.Size = new System.Drawing.Size(237, 375); rulesManager.TabIndex = 1; |
C# |
Copy Code
|
---|---|
//Set datasource for FlexGrid private DataTable GetDataSource() { var rs = "select * from Products;"; var cn = GetConnectionString(); var da = new OleDbDataAdapter(rs, cn); var dt = new DataTable(); da.Fill(dt); return dt; } static string GetConnectionString() { var path = Environment.GetFolderPath(Environment.SpecialFolder.Personal) + @"\ComponentOne Samples\Common"; var conn = @"provider=microsoft.jet.oledb.4.0;data source={0}\c1nwind.mdb;"; return string.Format(conn, path); } |
C# |
Copy Code
|
---|---|
flexGrid.DataSource = GetDataSource(); |
To integrate RulesManager with FlexGrid, use SetC1RulesManager method of the RulesManager class as shown in the following code:
C# |
Copy Code
|
---|---|
rulesManager.SetC1RulesManager(flexGrid, rulesManager); |
C# |
Copy Code
|
---|---|
private void ApplyPredefinedRules() { //Define the rule in RulesManager var rule1 = new C1.Win.RulesManager.Rule() { Name = "Many In Stock", Expression = "= [UnitsInStock] > 20", Style = new ItemStyle() { ForeColor = Color.White, BackColor = Color.Green } }; |
C# |
Copy Code
|
---|---|
rule1.AppliesTo.Add(new FieldRange(new string[] { "UnitsInStock" })); |
C# |
Copy Code
|
---|---|
rulesManager.Rules.Add(rule1); |
C# |
Copy Code
|
---|---|
ApplyPredefinedRules(); |
Observe that the rule you just created gets added in the RulesManager control and is applied to FlexGrid control.