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;
Or you could simplify this by using:
IEnumerable gridRows = this.ultraGrid1.Rows.GetAllNonGroupByRows();
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