/// <summary> /// Return a list of the values to display in the grid /// </summary> /// <param name="context"></param> /// <returns>A list of values the user can choose from</returns> public override StandardValuesCollection GetStandardValues (System.ComponentModel.ITypeDescriptorContext context) { // Try to get a store from the current context // "context.Instance" returns the element(s) that // are currently selected i.e. whose values are being // shown in the property grid. // Note that the user could have selected multiple objects, // in which case context.Instance will be an array. Store store = GetStore(context.Instance); DataGridSuperHeader sh = (DataGridSuperHeader)context.Instance; DataGrid dg = sh.DataGrid; List <string> values = new List <string>(); if (store != null) { foreach (ColumnAttribute col in dg.Columns) { values.Add(col.Name); } } values.Add(""); return(new StandardValuesCollection(values)); }
/// <summary> /// Attempts to get to a store from the currently selected object(s) /// in the property grid. /// </summary> private Store GetStore(object gridSelection) { // We assume that "instance" will either be a single model element, or // an array of model elements (if multiple items are selected). DataGridSuperHeader currentElement = null; object[] objects = gridSelection as object[]; if (objects != null && objects.Length > 0) { currentElement = objects[0] as DataGridSuperHeader; } else { currentElement = gridSelection as DataGridSuperHeader; } return((currentElement == null) ? null : currentElement.Store); }