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# |
コードのコピー
|
---|---|
this.productsTableAdapter.Fill(this.c1NWindDataSet.Products); |
To integrate RulesManager with FlexGrid, use the following code:
C# |
コードのコピー
|
---|---|
rulesManager.SetC1RulesManager(flexGrid, rulesManager); |
Property | Value |
---|---|
Name | Many In Stock |
Expression | = [UnitsInStock] > 20 |
Style > BackColor | Green |
Style > ForeColor | White |
C# |
コードのコピー
|
---|---|
C1FlexGrid c1FlexGrid = new C1FlexGrid(); C1RulesManager rulesManager = new C1RulesManager(); |
C# |
コードのコピー
|
---|---|
//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# |
コードのコピー
|
---|---|
flexGrid.DataSource = GetDataSource(); |
To integrate RulesManager with FlexGrid, use SetC1RulesManager method of the RulesManager class as shown in the following code:
C# |
コードのコピー
|
---|---|
rulesManager.SetC1RulesManager(flexGrid, rulesManager); |
C# |
コードのコピー
|
---|---|
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# |
コードのコピー
|
---|---|
rule1.AppliesTo.Add(new FieldRange(new string[] { "UnitsInStock" })); |
C# |
コードのコピー
|
---|---|
rulesManager.Rules.Add(rule1); |
C# |
コードのコピー
|
---|---|
ApplyPredefinedRules(); |