public string GetItemText(object item, string fieldName) { object propertyValue = GetPropertyValue(item, fieldName); if (!_FormattingEnabled) { if (item == null) { return string.Empty; } if (propertyValue == null) { return ""; } return Convert.ToString(propertyValue, CultureInfo.CurrentCulture); } TreeConvertEventArgs e = new TreeConvertEventArgs(propertyValue, typeof(string), item, fieldName); this.OnFormat(e); if ((e.Value != item) && (e.Value is string)) { return (string)e.Value; } if (stringTypeConverter == null) { stringTypeConverter = TypeDescriptor.GetConverter(typeof(string)); } try { return (string)FormatHelper.FormatObject(propertyValue, typeof(string), GetFieldConverter(fieldName), stringTypeConverter, _FormatString, _FormatInfo, null, DBNull.Value); } catch (Exception ex) { if (ex is SecurityException || IsCriticalException(ex)) { throw; } return ((propertyValue != null) ? Convert.ToString(item, CultureInfo.CurrentCulture) : ""); } }
/// <summary> /// Raises the Format event. /// </summary> /// <param name="e">Event parameters</param> protected virtual void OnFormat(TreeConvertEventArgs e) { TreeConvertEventHandler handler = Format; if (handler != null) { handler(this, e); } }