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
3555
Error: Trying to add a drop down in a row cell when in group by
posted

 

When the grid is not groupby a column, the code below work.  However, when it’s group by a column, (row.Cells["BrandGeneric"].Text == string.Empty) will throw an error null reference exepction for the row object.

 

We are trying to add a valuelist for the cells in a column whethere the grid has a column in group by or not. 

 

 

private void AddGenericBrandDropDown()

        {

            UltraGridBand band = this.grdPricingDrugCurrentTherapyDosing.DisplayLayout.Bands[0];

            foreach (UltraGridRow row in grdPricingDrugCurrentTherapyDosing.Rows)

            {

                if (row.Cells["BrandGeneric"].Text == string.Empty)

                {

                    // Add dropdownlist to the empty cell

 

                    ValueList brandGeneric;

 

                    if (!band.Layout.ValueLists.Exists("BrandGeneric"))

                    {

                        brandGeneric = band.Layout.ValueLists.Add("BrandGeneric");

                        brandGeneric.ValueListItems.Add(1, "Brand");

                        brandGeneric.ValueListItems.Add(2, "Generic");

                    }

                    row.Cells["BrandGeneric"].ValueList = band.Layout.ValueLists["BrandGeneric"];

                }

 

                else

                {

                    // Not allow edit mode if the cell alread has a value

                    row.Cells["BrandGeneric"].Activation = Activation.NoEdit;

                }               

            }

          

        }

Parents
No Data
Reply
  • 37774
    posted

     The reason for this is that when you have grouped a column, the root Rows collection contains all GroupByRows.  A better solution would be to use the GetRowEnumerator method:

     IEnumerable gridRows = this.ultraGrid1.Rows.GetRowEnumerator(GridRowType.DataRow, this.ultraGrid1.DisplayLayout.Bands[0], null);
    foreach (UltraGridRow row in gridRows)
    {
        // ...
    }

    -Matt

Children