Show message in empty cells in GridView

后端 未结 4 2015
野性不改
野性不改 2021-01-06 14:03

I\'m importing GridView from excel I need to show a message near every empty cell to give the user information about what it should be writing..



        
4条回答
  •  说谎
    说谎 (楼主)
    2021-01-06 14:29

    You can color the XtraGrid cells using Conditional Formatting feature:

    gridControl1.DataSource = new List { 
        new Person(){ Name = "John", Age = 25 },
        new Person(){ Name = "Mary", Age = 17 },
        new Person(){ Age = 17  },
        new Person(){ Name = "Ann" },
        new Person(){ Name = "Pit", Age = 5 },
    };
    StyleFormatCondition nameCondition = new StyleFormatCondition();
    nameCondition.Column = gridView1.Columns["Name"];
    nameCondition.Condition = FormatConditionEnum.Expression;
    nameCondition.Expression = "IsNullOrEmpty([Name])";
    nameCondition.Appearance.BackColor = Color.Red;
    nameCondition.Appearance.Options.UseBackColor = true;
    
    StyleFormatCondition ageCondition = new StyleFormatCondition();
    ageCondition.Column = gridView1.Columns["Age"];
    ageCondition.Condition = FormatConditionEnum.Expression;
    ageCondition.Expression = "[Age]<10";
    ageCondition.Appearance.BackColor = Color.Maroon;
    ageCondition.Appearance.Options.UseBackColor = true;
    
    gridView1.FormatConditions.AddRange(new StyleFormatCondition[] { 
        nameCondition, ageCondition
    });
    

    Result:
    XtraGrid Conditional Formatting

    Related Links:
    Customizing Appearances of Individual Rows and Cells
    Style Format Conditions
    Custom Painting (Samples)

提交回复
热议问题