Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
60
Cells validation on button click event
posted

Hi,

I have a ultrawingrid (only few columns are editable) which is populated on page_load, user enters values or selects a value from dropdown.

On a button click event I should validate all the editable cells of the grid for null values and highlight all the null values cells with some background color.

Thanks

  • 20872
    Verified Answer
    Offline posted

    Hello Ramesh925,

    I have implement two possible approaches for you in the code shown at the end of the forum thread.

    In the first approach I am iterating through all the cells and setting the Red backColor of those that match the null condition. (ultraButton1_Click)

    In the second approach I am setting the valueBased appearance on the desired columns
    (ultraButton2_Click)

    Please let me me know if you have any other questions with this matter.

     

          OperatorCondition condition1;
            Infragistics.Win.Appearance appearance;
            ConditionValueAppearance valAppearance;
            public Form1()
            {
                InitializeComponent();
                DataTable dt = new DataTable();
                dt.Columns.Add("String1", typeof(string));
                dt.Columns.Add("String2", typeof(string));
                dt.Columns.Add("String3", typeof(string));
    
                dt.Rows.Add("a", null, "c");
                dt.Rows.Add("a", "b", "c");
                dt.Rows.Add("a", "b", null);
                dt.Rows.Add(null, "b", "c");
                dt.Rows.Add("a", null, "c");
                dt.Rows.Add("a", null, "c");
                dt.Rows.Add("a", null, "c");
                dt.Rows.Add("a", "b", null);
                dt.Rows.Add(null, "b", "c");
    
    
                ultraGrid1.DataSource = dt.DefaultView;
    
                condition1 = new OperatorCondition(ConditionOperator.IsNullOrEmpty, DBNull.Value);
                appearance = new Infragistics.Win.Appearance();
                appearance.BackColor = Color.Green;
                valAppearance = new ConditionValueAppearance();
                valAppearance.Add(condition1, appearance);
    
            }
    
            private void ultraButton1_Click(object sender, EventArgs e)
            {
                foreach (UltraGridRow row in ultraGrid1.Rows)
                {
                    foreach (UltraGridCell cell in row.Cells)
                    {
                        if (cell.Value == DBNull.Value)
                        {
                            cell.Appearance.BackColor = Color.Red;
                        }
                    }
                }
             }
    
            private void ultraButton2_Click(object sender, EventArgs e)
            {
                ultraGrid1.DisplayLayout.Bands[0].Columns["String1"].ValueBasedAppearance = valAppearance;
            }
        }