Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / ndp / fx / src / xsp / System / Web / UI / WebControls / Listbox.cs / 1 / Listbox.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Web.UI.WebControls {
using System;
using System.Collections;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Drawing;
using System.Globalization;
using System.Web;
using System.Web.UI;
using System.Security.Permissions;
///
/// Constructs a list box and defines its
/// properties.
///
[
ValidationProperty("SelectedItem"),
SupportsEventValidation
]
[AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)]
public class ListBox : ListControl, IPostBackDataHandler {
///
/// Initializes a new instance of the class.
///
public ListBox() {
}
///
/// [To be supplied.]
///
[
Browsable(false)
]
public override Color BorderColor {
get {
return base.BorderColor;
}
set {
base.BorderColor = value;
}
}
///
/// [To be supplied.]
///
[
Browsable(false)
]
public override BorderStyle BorderStyle {
get {
return base.BorderStyle;
}
set {
base.BorderStyle = value;
}
}
///
/// [To be supplied.]
///
[
Browsable(false)
]
public override Unit BorderWidth {
get {
return base.BorderWidth;
}
set {
base.BorderWidth = value;
}
}
internal override bool IsMultiSelectInternal {
get {
return SelectionMode == ListSelectionMode.Multiple;
}
}
///
/// Gets or
/// sets the display height (in rows) of the list box.
///
[
WebCategory("Appearance"),
DefaultValue(4),
WebSysDescription(SR.ListBox_Rows)
]
public virtual int Rows {
get {
object n = ViewState["Rows"];
return((n == null) ? 4 : (int)n);
}
set {
if (value < 1) {
throw new ArgumentOutOfRangeException("value");
}
ViewState["Rows"] = value;
}
}
///
/// Gets or sets
/// the selection behavior of the list box.
///
[
WebCategory("Behavior"),
DefaultValue(ListSelectionMode.Single),
WebSysDescription(SR.ListBox_SelectionMode)
]
public virtual ListSelectionMode SelectionMode {
get {
object sm = ViewState["SelectionMode"];
return((sm == null) ? ListSelectionMode.Single : (ListSelectionMode)sm);
}
set {
if (value < ListSelectionMode.Single || value > ListSelectionMode.Multiple) {
throw new ArgumentOutOfRangeException("value");
}
ViewState["SelectionMode"] = value;
}
}
///
protected override void AddAttributesToRender(HtmlTextWriter writer) {
writer.AddAttribute(HtmlTextWriterAttribute.Size,
Rows.ToString(NumberFormatInfo.InvariantInfo));
string uniqueID = UniqueID;
if (uniqueID != null) {
writer.AddAttribute(HtmlTextWriterAttribute.Name, uniqueID);
}
base.AddAttributesToRender(writer);
}
public virtual int[] GetSelectedIndices() {
return (int[])SelectedIndicesInternal.ToArray(typeof(int));
}
///
///
///
protected internal override void OnPreRender(EventArgs e) {
base.OnPreRender(e);
if (Page != null && SelectionMode == ListSelectionMode.Multiple && Enabled) {
// ensure postback when no item is selected
Page.RegisterRequiresPostBack(this);
}
}
///
///
/// Loads the posted content of the list control if it is different from the last
/// posting.
///
bool IPostBackDataHandler.LoadPostData(String postDataKey, NameValueCollection postCollection) {
return LoadPostData(postDataKey, postCollection);
}
///
///
/// Loads the posted content of the list control if it is different from the last
/// posting.
///
protected virtual bool LoadPostData(String postDataKey, NameValueCollection postCollection) {
if (IsEnabled == false) {
// When a ListBox is disabled, then there is no postback
// data for it. Any checked state information has been loaded
// via view state.
return false;
}
string[] selectedItems = postCollection.GetValues(postDataKey);
bool selectionChanged = false;
EnsureDataBound();
if (selectedItems != null) {
if (SelectionMode == ListSelectionMode.Single) {
ValidateEvent(postDataKey, selectedItems[0]);
int n = Items.FindByValueInternal(selectedItems[0], false);
if (SelectedIndex != n) {
SetPostDataSelection(n);
selectionChanged = true;
}
}
else { // multiple selection
int count = selectedItems.Length;
ArrayList oldSelectedIndices = SelectedIndicesInternal;
ArrayList newSelectedIndices = new ArrayList(count);
for (int i=0; i < count; i++) {
ValidateEvent(postDataKey, selectedItems[i]);
// create array of new indices from posted values
newSelectedIndices.Add(Items.FindByValueInternal(selectedItems[i], false));
}
int oldcount = 0;
if (oldSelectedIndices != null)
oldcount = oldSelectedIndices.Count;
if (oldcount == count) {
// check new indices against old indices
// assumes selected values are posted in order
for (int i=0; i < count; i++) {
if (((int)newSelectedIndices[i]) != ((int)oldSelectedIndices[i])) {
selectionChanged = true;
break;
}
}
}
else {
// indices must have changed if count is different
selectionChanged = true;
}
if (selectionChanged) {
// select new indices
SelectInternal(newSelectedIndices);
}
}
}
else { // no items selected
if (SelectedIndex != -1) {
SetPostDataSelection(-1);
selectionChanged = true;
}
}
return selectionChanged;
}
///
///
/// Invokes the OnSelectedIndexChanged method whenever posted data
/// for the control has changed.
///
void IPostBackDataHandler.RaisePostDataChangedEvent() {
RaisePostDataChangedEvent();
}
///
///
/// Invokes the OnSelectedIndexChanged method whenever posted data
/// for the control has changed.
///
protected virtual void RaisePostDataChangedEvent() {
if (AutoPostBack && !Page.IsPostBackEventControlRegistered) {
// VSWhidbey 204824
Page.AutoPostBackControl = this;
if (CausesValidation) {
Page.Validate(ValidationGroup);
}
}
OnSelectedIndexChanged(EventArgs.Empty);
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Web.UI.WebControls {
using System;
using System.Collections;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Drawing;
using System.Globalization;
using System.Web;
using System.Web.UI;
using System.Security.Permissions;
///
/// Constructs a list box and defines its
/// properties.
///
[
ValidationProperty("SelectedItem"),
SupportsEventValidation
]
[AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)]
public class ListBox : ListControl, IPostBackDataHandler {
///
/// Initializes a new instance of the class.
///
public ListBox() {
}
///
/// [To be supplied.]
///
[
Browsable(false)
]
public override Color BorderColor {
get {
return base.BorderColor;
}
set {
base.BorderColor = value;
}
}
///
/// [To be supplied.]
///
[
Browsable(false)
]
public override BorderStyle BorderStyle {
get {
return base.BorderStyle;
}
set {
base.BorderStyle = value;
}
}
///
/// [To be supplied.]
///
[
Browsable(false)
]
public override Unit BorderWidth {
get {
return base.BorderWidth;
}
set {
base.BorderWidth = value;
}
}
internal override bool IsMultiSelectInternal {
get {
return SelectionMode == ListSelectionMode.Multiple;
}
}
///
/// Gets or
/// sets the display height (in rows) of the list box.
///
[
WebCategory("Appearance"),
DefaultValue(4),
WebSysDescription(SR.ListBox_Rows)
]
public virtual int Rows {
get {
object n = ViewState["Rows"];
return((n == null) ? 4 : (int)n);
}
set {
if (value < 1) {
throw new ArgumentOutOfRangeException("value");
}
ViewState["Rows"] = value;
}
}
///
/// Gets or sets
/// the selection behavior of the list box.
///
[
WebCategory("Behavior"),
DefaultValue(ListSelectionMode.Single),
WebSysDescription(SR.ListBox_SelectionMode)
]
public virtual ListSelectionMode SelectionMode {
get {
object sm = ViewState["SelectionMode"];
return((sm == null) ? ListSelectionMode.Single : (ListSelectionMode)sm);
}
set {
if (value < ListSelectionMode.Single || value > ListSelectionMode.Multiple) {
throw new ArgumentOutOfRangeException("value");
}
ViewState["SelectionMode"] = value;
}
}
///
protected override void AddAttributesToRender(HtmlTextWriter writer) {
writer.AddAttribute(HtmlTextWriterAttribute.Size,
Rows.ToString(NumberFormatInfo.InvariantInfo));
string uniqueID = UniqueID;
if (uniqueID != null) {
writer.AddAttribute(HtmlTextWriterAttribute.Name, uniqueID);
}
base.AddAttributesToRender(writer);
}
public virtual int[] GetSelectedIndices() {
return (int[])SelectedIndicesInternal.ToArray(typeof(int));
}
///
///
///
protected internal override void OnPreRender(EventArgs e) {
base.OnPreRender(e);
if (Page != null && SelectionMode == ListSelectionMode.Multiple && Enabled) {
// ensure postback when no item is selected
Page.RegisterRequiresPostBack(this);
}
}
///
///
/// Loads the posted content of the list control if it is different from the last
/// posting.
///
bool IPostBackDataHandler.LoadPostData(String postDataKey, NameValueCollection postCollection) {
return LoadPostData(postDataKey, postCollection);
}
///
///
/// Loads the posted content of the list control if it is different from the last
/// posting.
///
protected virtual bool LoadPostData(String postDataKey, NameValueCollection postCollection) {
if (IsEnabled == false) {
// When a ListBox is disabled, then there is no postback
// data for it. Any checked state information has been loaded
// via view state.
return false;
}
string[] selectedItems = postCollection.GetValues(postDataKey);
bool selectionChanged = false;
EnsureDataBound();
if (selectedItems != null) {
if (SelectionMode == ListSelectionMode.Single) {
ValidateEvent(postDataKey, selectedItems[0]);
int n = Items.FindByValueInternal(selectedItems[0], false);
if (SelectedIndex != n) {
SetPostDataSelection(n);
selectionChanged = true;
}
}
else { // multiple selection
int count = selectedItems.Length;
ArrayList oldSelectedIndices = SelectedIndicesInternal;
ArrayList newSelectedIndices = new ArrayList(count);
for (int i=0; i < count; i++) {
ValidateEvent(postDataKey, selectedItems[i]);
// create array of new indices from posted values
newSelectedIndices.Add(Items.FindByValueInternal(selectedItems[i], false));
}
int oldcount = 0;
if (oldSelectedIndices != null)
oldcount = oldSelectedIndices.Count;
if (oldcount == count) {
// check new indices against old indices
// assumes selected values are posted in order
for (int i=0; i < count; i++) {
if (((int)newSelectedIndices[i]) != ((int)oldSelectedIndices[i])) {
selectionChanged = true;
break;
}
}
}
else {
// indices must have changed if count is different
selectionChanged = true;
}
if (selectionChanged) {
// select new indices
SelectInternal(newSelectedIndices);
}
}
}
else { // no items selected
if (SelectedIndex != -1) {
SetPostDataSelection(-1);
selectionChanged = true;
}
}
return selectionChanged;
}
///
///
/// Invokes the OnSelectedIndexChanged method whenever posted data
/// for the control has changed.
///
void IPostBackDataHandler.RaisePostDataChangedEvent() {
RaisePostDataChangedEvent();
}
///
///
/// Invokes the OnSelectedIndexChanged method whenever posted data
/// for the control has changed.
///
protected virtual void RaisePostDataChangedEvent() {
if (AutoPostBack && !Page.IsPostBackEventControlRegistered) {
// VSWhidbey 204824
Page.AutoPostBackControl = this;
if (CausesValidation) {
Page.Validate(ValidationGroup);
}
}
OnSelectedIndexChanged(EventArgs.Empty);
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- EventMappingSettingsCollection.cs
- X509Certificate.cs
- MimeTypeMapper.cs
- WindowVisualStateTracker.cs
- DataGridColumn.cs
- RightsManagementInformation.cs
- XmlSerializationGeneratedCode.cs
- Event.cs
- MemberNameValidator.cs
- CapacityStreamGeometryContext.cs
- TextAction.cs
- ColumnProvider.cs
- Rfc2898DeriveBytes.cs
- WpfSharedBamlSchemaContext.cs
- TypeListConverter.cs
- DesignSurfaceCollection.cs
- CodeDOMProvider.cs
- PropertyCondition.cs
- ResourceType.cs
- StylusDevice.cs
- XmlnsPrefixAttribute.cs
- TextFormatter.cs
- UnsafeNativeMethods.cs
- XmlQueryCardinality.cs
- HebrewCalendar.cs
- SiteMapHierarchicalDataSourceView.cs
- SpeechSeg.cs
- MorphHelper.cs
- ControllableStoryboardAction.cs
- EntityKeyElement.cs
- ExeConfigurationFileMap.cs
- cookieexception.cs
- ExternalCalls.cs
- EntityType.cs
- CompilationLock.cs
- WebPartDescriptionCollection.cs
- SqlNotificationRequest.cs
- basecomparevalidator.cs
- SubMenuStyleCollection.cs
- ArrayElementGridEntry.cs
- TabletCollection.cs
- ProcessModuleCollection.cs
- SrgsElementFactoryCompiler.cs
- TableItemStyle.cs
- SoapFaultCodes.cs
- StaticFileHandler.cs
- InvokePattern.cs
- CannotUnloadAppDomainException.cs
- DBDataPermission.cs
- PanelStyle.cs
- Menu.cs
- DesignTimeXamlWriter.cs
- ObservableDictionary.cs
- SourceInterpreter.cs
- DataStreamFromComStream.cs
- CLSCompliantAttribute.cs
- ProjectionCamera.cs
- HMACSHA256.cs
- UInt32Storage.cs
- IApplicationTrustManager.cs
- Socket.cs
- PlainXmlSerializer.cs
- DbMetaDataColumnNames.cs
- RelationshipType.cs
- FileFormatException.cs
- IdentitySection.cs
- XPathArrayIterator.cs
- HttpCacheVaryByContentEncodings.cs
- LineBreak.cs
- ServiceContractGenerationContext.cs
- WpfGeneratedKnownTypes.cs
- RegisteredDisposeScript.cs
- NativeMethods.cs
- ContentFilePart.cs
- RangeContentEnumerator.cs
- BitmapImage.cs
- DocobjHost.cs
- Camera.cs
- MenuItemBindingCollection.cs
- Reference.cs
- TextBlock.cs
- UnmanagedHandle.cs
- AuthenticationConfig.cs
- Resources.Designer.cs
- SessionEndingCancelEventArgs.cs
- SynchronizedPool.cs
- VirtualPathUtility.cs
- Atom10FeedFormatter.cs
- _LazyAsyncResult.cs
- FunctionNode.cs
- WebColorConverter.cs
- TypeConverterHelper.cs
- WebBrowserUriTypeConverter.cs
- HandledEventArgs.cs
- ProxyHwnd.cs
- TdsEnums.cs
- AttributeQuery.cs
- DataContractAttribute.cs
- CodeGenerator.cs
- XdrBuilder.cs