public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) { if (context is not null && context.Instance is not null) { object instance = context.Instance; PropertyDescriptor imageListProp = ImageListUtils.GetImageListProperty(context.PropertyDescriptor, ref instance); while (instance is not null && imageListProp is null) { PropertyDescriptorCollection props = TypeDescriptor.GetProperties(instance); foreach (PropertyDescriptor prop in props) { if (typeof(ImageList).IsAssignableFrom(prop.PropertyType)) { imageListProp = prop; break; } } if (imageListProp is null) { // We didn't find the image list in this component. See if the // component has a "parent" property. If so, walk the tree... PropertyDescriptor parentProp = props[ParentImageListProperty]; if (parentProp is not null) { instance = parentProp.GetValue(instance); } else { // Stick a fork in us, we're done. instance = null; } } } if (imageListProp is not null) { ImageList imageList = (ImageList)imageListProp.GetValue(instance); if (imageList is not null) { // Create array to contain standard values // object[] values; int nImages = imageList.Images.Count + 2; values = new object[nImages]; values[nImages - 2] = ImageList.Indexer.DefaultIndex; values[nImages - 1] = -2; // Fill in the array for (int i = 0; i < nImages - 2; i++) { values[i] = i; } return(new StandardValuesCollection(values)); } } } return(new StandardValuesCollection(new object[] { ImageList.Indexer.DefaultIndex, ImageList.Indexer.NoneIndex })); }
private void parent_PositionChanged(object sender, EventArgs args) { SetDataSource(prop_desc.GetValue(parent.Current)); }
private void ParentManager_CurrentItemChanged(object sender, EventArgs e) { if (IgnoreItemChangedTable.Contains(parentManager)) { return; } int oldlistposition = listposition; // we only pull the data from the controls into the backEnd. we do not care about keeping the lastGoodKnownRow // when we are about to change the entire list in this currencymanager. try { PullData(); } catch (Exception ex) { OnDataError(ex); } if (parentManager is CurrencyManager curManager) { if (curManager.Count > 0) { // Parent list has a current row, so get the related list from the relevant property on that row. SetDataSource(fieldInfo.GetValue(curManager.Current)); listposition = (Count > 0 ? 0 : -1); } else { // APPCOMPAT: bring back the Everett behavior where the currency manager adds an item and // then it cancels the addition. // // really, really hocky. // will throw if the list in the curManager is not IBindingList // and this will fail if the IBindingList does not have list change notification. read on.... // when a new item will get added to an empty parent table, // the table will fire OnCurrentChanged and this method will get executed again // allowing us to set the data source to an object with the right properties (so we can show // metadata at design time). // we then call CancelCurrentEdit to remove the dummy row, but making sure to ignore any // OnCurrentItemChanged that results from this action (to avoid infinite recursion) curManager.AddNew(); try { IgnoreItemChangedTable.Add(curManager); curManager.CancelCurrentEdit(); } finally { if (IgnoreItemChangedTable.Contains(curManager)) { IgnoreItemChangedTable.Remove(curManager); } } } } else { // Case where the parent is not a list, but a single object SetDataSource(fieldInfo.GetValue(parentManager.Current)); listposition = (Count > 0 ? 0 : -1); } if (oldlistposition != listposition) { OnPositionChanged(EventArgs.Empty); } OnCurrentChanged(EventArgs.Empty); OnCurrentItemChanged(EventArgs.Empty); }
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) { if (context != null && context.Instance != null) { object instance = context.Instance; ImageList imageList = null; PropertyDescriptorCollection listViewItemProps = TypeDescriptor.GetProperties(instance); PropertyDescriptor listViewProp = listViewItemProps["ListView"]; if (listViewProp != null) { // Grab the ListView property off of the TreeNode. object listViewInstance = listViewProp.GetValue(instance); if (listViewInstance != null) { // Get the ImageList property from the ListView and set it to be the currentImageList. PropertyDescriptorCollection listViewProps = TypeDescriptor.GetProperties(listViewInstance); PropertyDescriptor listViewImageListProperty = listViewProps["StateImageList"]; if (listViewImageListProperty != null) { imageList = (ImageList)listViewImageListProperty.GetValue(listViewInstance); } } } if (imageList != null) { // Create array to contain standard values // object[] values; int nImages = imageList.Images.Count; if (IncludeNoneAsStandardValue) { values = new object[nImages + 1]; values[nImages] = -1; } else { values = new object[nImages]; } // Fill in the array // for (int i = 0; i < nImages; i++) { values[i] = i; } return(new StandardValuesCollection(values)); } } if (IncludeNoneAsStandardValue) { return(new StandardValuesCollection(new object[] { -1 })); } else { return(new StandardValuesCollection(Array.Empty <object>())); } }
void PushData(bool force) { if (manager == null || manager.IsSuspended || manager.Count == 0 || manager.Position == -1) { return; } #if NET_2_0 if (!force && control_update_mode == ControlUpdateMode.Never) { return; } #endif if (is_null_desc != null) { bool is_null = (bool)is_null_desc.GetValue(manager.Current); if (is_null) { data = Convert.DBNull; return; } } PropertyDescriptor pd = TypeDescriptor.GetProperties(manager.Current).Find(binding_member_info.BindingField, true); if (pd == null) { data = manager.Current; } else { data = pd.GetValue(manager.Current); } #if NET_2_0 if ((data == null || data == DBNull.Value) && null_value != null) { data = null_value; } #endif try { data = FormatData(data); SetControlValue(data); } catch (Exception e) { #if NET_2_0 if (formatting_enabled) { FireBindingComplete(BindingCompleteContext.ControlUpdate, e, e.Message); return; } #endif throw e; } #if NET_2_0 if (formatting_enabled) { FireBindingComplete(BindingCompleteContext.ControlUpdate, null, null); } #endif }
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) { if (context != null && context.Instance != null) { object instance = context.Instance; PropertyDescriptor imageListProp = ImageListUtils.GetImageListProperty(context.PropertyDescriptor, ref instance); while (instance != null && imageListProp is null) { PropertyDescriptorCollection props = TypeDescriptor.GetProperties(instance); foreach (PropertyDescriptor prop in props) { if (typeof(ImageList).IsAssignableFrom(prop.PropertyType)) { imageListProp = prop; break; } } if (imageListProp is null) { // We didn't find the image list in this component. See if the // component has a "parent" property. If so, walk the tree... // PropertyDescriptor parentProp = props[ParentImageListProperty]; if (parentProp != null) { instance = parentProp.GetValue(instance); } else { // Stick a fork in us, we're done. // instance = null; } } } if (imageListProp != null) { ImageList imageList = (ImageList)imageListProp.GetValue(instance); if (imageList != null) { // Create array to contain standard values // object[] values; int nImages = imageList.Images.Count; if (IncludeNoneAsStandardValue) { values = new object[nImages + 1]; values[nImages] = -1; } else { values = new object[nImages]; } // Fill in the array // for (int i = 0; i < nImages; i++) { values[i] = i; } return(new StandardValuesCollection(values)); } } } if (IncludeNoneAsStandardValue) { return(new StandardValuesCollection(new object[] { -1 })); } else { return(new StandardValuesCollection(Array.Empty <object>())); } }
private void ParentManager_CurrentChanged(object sender, EventArgs e) { EndCurrentEdit(); SetDataSource(fieldInfo.GetValue(parentManager.Current)); OnCurrentChanged(EventArgs.Empty); }
public override TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) { if ((context != null) && (context.Instance != null)) { object instance = context.Instance; PropertyDescriptor imageListProperty = ImageListUtils.GetImageListProperty(context.PropertyDescriptor, ref instance); while ((instance != null) && (imageListProperty == null)) { PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(instance); foreach (PropertyDescriptor descriptor2 in properties) { if (typeof(ImageList).IsAssignableFrom(descriptor2.PropertyType)) { imageListProperty = descriptor2; break; } } if (imageListProperty == null) { PropertyDescriptor descriptor3 = properties[this.ParentImageListProperty]; if (descriptor3 != null) { instance = descriptor3.GetValue(instance); continue; } instance = null; } } if (imageListProperty != null) { ImageList list = (ImageList)imageListProperty.GetValue(instance); if (list != null) { object[] objArray; int count = list.Images.Count; if (this.IncludeNoneAsStandardValue) { objArray = new object[count + 1]; objArray[count] = ""; } else { objArray = new object[count]; } StringCollection keys = list.Images.Keys; for (int i = 0; i < keys.Count; i++) { if ((keys[i] != null) && (keys[i].Length != 0)) { objArray[i] = keys[i]; } } return(new TypeConverter.StandardValuesCollection(objArray)); } } } if (this.IncludeNoneAsStandardValue) { return(new TypeConverter.StandardValuesCollection(new object[] { "" })); } return(new TypeConverter.StandardValuesCollection(new object[0])); }