Code:
/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / ndp / fx / src / Designer / WinForms / System / WinForms / Design / listviewsubitemcollectioneditor.cs / 1 / listviewsubitemcollectioneditor.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Scope="member", Target="System.Windows.Forms.Design.ListViewSubItemCollectionEditor..ctor(System.Type)")]
namespace System.Windows.Forms.Design {
using System.Runtime.InteropServices;
using System.Diagnostics;
using System;
using System.IO;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Windows.Forms;
using System.Drawing;
using System.Design;
using System.Drawing.Design;
using System.Windows.Forms.ComponentModel;
///
///
///
/// Provides an editor for an image collection.
///
internal class ListViewSubItemCollectionEditor : CollectionEditor {
private static int count = 0;
ListViewItem.ListViewSubItem firstSubItem = null;
///
///
/// Initializes a new instance of the class.
///
public ListViewSubItemCollectionEditor(Type type) : base(type){
}
///
///
/// Creates an instance of the specified type in the collection.
///
// VSWhidbey 122909: Set the Name property in the item's properties.
protected override object CreateInstance(Type type) {
object instance = base.CreateInstance(type);
// slap in a default site-like name
if (instance is ListViewItem.ListViewSubItem) {
((ListViewItem.ListViewSubItem)instance).Name = SR.GetString(SR.ListViewSubItemBaseName) + count++;
}
return instance;
}
///
///
/// Retrieves the display text for the given list sub item.
///
protected override string GetDisplayText(object value) {
string text;
if (value == null) {
return string.Empty;
}
PropertyDescriptor prop = TypeDescriptor.GetDefaultProperty(CollectionType);
if (prop != null && prop.PropertyType == typeof(string)) {
text = (string)prop.GetValue(value);
if (text != null && text.Length > 0) {
return text;
}
}
text = TypeDescriptor.GetConverter(value).ConvertToString(value);
if (text == null || text.Length == 0) {
text = value.GetType().Name;
}
return text;
}
///
protected override object[] GetItems(object editValue) {
// take the fist sub item out of the collection
ListViewItem.ListViewSubItemCollection subItemsColl = (ListViewItem.ListViewSubItemCollection) editValue;
// add all the other sub items
object[] values = new object[subItemsColl.Count];
((ICollection)subItemsColl).CopyTo(values, 0);
if (values.Length > 0) {
// save the first sub item
firstSubItem = subItemsColl[0];
// now return the rest.
//
object[] subValues = new object[values.Length - 1];
Array.Copy(values, 1, subValues, 0, subValues.Length);
values = subValues;
}
return values;
}
///
protected override object SetItems(object editValue, object[] value) {
IList list = editValue as IList;
list.Clear();
list.Add(firstSubItem);
for (int i = 0; i < value.Length; i ++) {
list.Add(value[i]);
}
return editValue;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- UriTemplateLiteralPathSegment.cs
- AuthenticationConfig.cs
- ProfileSettings.cs
- XamlClipboardData.cs
- HebrewCalendar.cs
- DockPatternIdentifiers.cs
- DrawingVisual.cs
- SelectedGridItemChangedEvent.cs
- SerializerWriterEventHandlers.cs
- Crc32.cs
- MembershipSection.cs
- PropertyInformationCollection.cs
- XPathParser.cs
- SafeNativeMethods.cs
- Rijndael.cs
- OleDbTransaction.cs
- Int16AnimationBase.cs
- HostExecutionContextManager.cs
- WizardStepBase.cs
- PageWrapper.cs
- WindowsAuthenticationEventArgs.cs
- processwaithandle.cs
- InternalPolicyElement.cs
- HttpResponseMessageProperty.cs
- FormatterConverter.cs
- PrintDialog.cs
- Input.cs
- BuildProviderCollection.cs
- DirectoryNotFoundException.cs
- SimpleTableProvider.cs
- BinaryObjectReader.cs
- ApplicationId.cs
- AuthenticationModulesSection.cs
- WriteTimeStream.cs
- FixedSOMLineRanges.cs
- LongCountAggregationOperator.cs
- TimelineClockCollection.cs
- Propagator.Evaluator.cs
- codemethodreferenceexpression.cs
- DataContractSerializerServiceBehavior.cs
- ScriptManager.cs
- SettingsPropertyNotFoundException.cs
- elementinformation.cs
- AssemblyName.cs
- ElementHostPropertyMap.cs
- IResourceProvider.cs
- TrustSection.cs
- OracleFactory.cs
- SqlDataSourceView.cs
- DetailsViewInsertedEventArgs.cs
- ZipIOLocalFileBlock.cs
- UIElement3DAutomationPeer.cs
- XmlValueConverter.cs
- ContextMarshalException.cs
- TypedElement.cs
- CodeSnippetStatement.cs
- SqlFactory.cs
- HtmlHistory.cs
- DocumentPageViewAutomationPeer.cs
- StringSource.cs
- LongValidatorAttribute.cs
- panel.cs
- BoundField.cs
- DesignerDataStoredProcedure.cs
- GPStream.cs
- HtmlMobileTextWriter.cs
- TraceContextRecord.cs
- ComNativeDescriptor.cs
- PersonalizationState.cs
- XPathChildIterator.cs
- TrackingProfileSerializer.cs
- DispatchWrapper.cs
- Parsers.cs
- SerializationObjectManager.cs
- Form.cs
- DataContractSerializerOperationFormatter.cs
- GuidelineSet.cs
- BaseTemplateParser.cs
- HashRepartitionStream.cs
- AccessViolationException.cs
- DataGridLinkButton.cs
- ParagraphVisual.cs
- QuaternionKeyFrameCollection.cs
- UndoManager.cs
- InvalidDataException.cs
- StaticExtensionConverter.cs
- XmlSerializerAssemblyAttribute.cs
- MimeParameterWriter.cs
- SmiXetterAccessMap.cs
- WebUtil.cs
- LeaseManager.cs
- SizeAnimation.cs
- FtpCachePolicyElement.cs
- CounterCreationData.cs
- PropertyItemInternal.cs
- GroupBox.cs
- EncodingNLS.cs
- ParameterCollection.cs
- ConvertersCollection.cs
- WebAdminConfigurationHelper.cs