Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / ndp / fx / src / WinForms / Managed / System / WinForms / DataGridViewCellLinkedList.cs / 1 / DataGridViewCellLinkedList.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Windows.Forms
{
using System;
using System.Diagnostics;
using System.Collections;
using System.Windows.Forms;
using System.ComponentModel;
///
///
/// Represents a linked list of objects
///
internal class DataGridViewCellLinkedList : IEnumerable
{
private DataGridViewCellLinkedListElement lastAccessedElement;
private DataGridViewCellLinkedListElement headElement;
private int count, lastAccessedIndex;
///
IEnumerator IEnumerable.GetEnumerator()
{
return new DataGridViewCellLinkedListEnumerator(this.headElement);
}
///
public DataGridViewCellLinkedList()
{
this.lastAccessedIndex = -1;
}
///
public DataGridViewCell this[int index]
{
get
{
Debug.Assert(index >= 0);
Debug.Assert(index < this.count);
if (this.lastAccessedIndex == -1 || index < this.lastAccessedIndex)
{
DataGridViewCellLinkedListElement tmp = this.headElement;
int tmpIndex = index;
while (tmpIndex > 0)
{
tmp = tmp.Next;
tmpIndex--;
}
this.lastAccessedElement = tmp;
this.lastAccessedIndex = index;
return tmp.DataGridViewCell;
}
else
{
while (this.lastAccessedIndex < index)
{
this.lastAccessedElement = this.lastAccessedElement.Next;
this.lastAccessedIndex++;
}
return this.lastAccessedElement.DataGridViewCell;
}
}
}
///
public int Count
{
get
{
return this.count;
}
}
///
public DataGridViewCell HeadCell
{
get
{
Debug.Assert(this.headElement != null);
return this.headElement.DataGridViewCell;
}
}
///
public void Add(DataGridViewCell dataGridViewCell)
{
Debug.Assert(dataGridViewCell != null);
Debug.Assert(dataGridViewCell.DataGridView.SelectionMode == DataGridViewSelectionMode.CellSelect ||
dataGridViewCell.DataGridView.SelectionMode == DataGridViewSelectionMode.ColumnHeaderSelect ||
dataGridViewCell.DataGridView.SelectionMode == DataGridViewSelectionMode.RowHeaderSelect);
DataGridViewCellLinkedListElement newHead = new DataGridViewCellLinkedListElement(dataGridViewCell);
if (this.headElement != null)
{
newHead.Next = this.headElement;
}
this.headElement = newHead;
this.count++;
this.lastAccessedElement = null;
this.lastAccessedIndex = -1;
}
///
public void Clear()
{
this.lastAccessedElement = null;
this.lastAccessedIndex = -1;
this.headElement = null;
this.count = 0;
}
///
public bool Contains(DataGridViewCell dataGridViewCell)
{
Debug.Assert(dataGridViewCell != null);
int index = 0;
DataGridViewCellLinkedListElement tmp = this.headElement;
while (tmp != null)
{
if (tmp.DataGridViewCell == dataGridViewCell)
{
this.lastAccessedElement = tmp;
this.lastAccessedIndex = index;
return true;
}
tmp = tmp.Next;
index++;
}
return false;
}
///
public bool Remove(DataGridViewCell dataGridViewCell)
{
Debug.Assert(dataGridViewCell != null);
DataGridViewCellLinkedListElement tmp1 = null, tmp2 = this.headElement;
while (tmp2 != null)
{
if (tmp2.DataGridViewCell == dataGridViewCell)
{
break;
}
tmp1 = tmp2;
tmp2 = tmp2.Next;
}
if (tmp2.DataGridViewCell == dataGridViewCell)
{
DataGridViewCellLinkedListElement tmp3 = tmp2.Next;
if (tmp1 == null)
{
this.headElement = tmp3;
}
else
{
tmp1.Next = tmp3;
}
this.count--;
this.lastAccessedElement = null;
this.lastAccessedIndex = -1;
return true;
}
return false;
}
/* Unused for now
///
public DataGridViewCell RemoveHead()
{
if (this.headElement == null)
{
return null;
}
DataGridViewCellLinkedListElement tmp = this.headElement;
this.headElement = tmp.Next;
this.count--;
this.lastAccessedElement = null;
this.lastAccessedIndex = -1;
return tmp.DataGridViewCell;
}
*/
///
public int RemoveAllCellsAtBand(bool column, int bandIndex)
{
int removedCount = 0;
DataGridViewCellLinkedListElement tmp1 = null, tmp2 = this.headElement;
while (tmp2 != null)
{
if ((column && tmp2.DataGridViewCell.ColumnIndex == bandIndex) ||
(!column && tmp2.DataGridViewCell.RowIndex == bandIndex))
{
DataGridViewCellLinkedListElement tmp3 = tmp2.Next;
if (tmp1 == null)
{
this.headElement = tmp3;
}
else
{
tmp1.Next = tmp3;
}
tmp2 = tmp3;
this.count--;
this.lastAccessedElement = null;
this.lastAccessedIndex = -1;
removedCount++;
}
else
{
tmp1 = tmp2;
tmp2 = tmp2.Next;
}
}
return removedCount;
}
}
///
///
/// Represents an emunerator of elements in a linked list.
///
internal class DataGridViewCellLinkedListEnumerator : IEnumerator
{
private DataGridViewCellLinkedListElement headElement;
private DataGridViewCellLinkedListElement current;
private bool reset;
///
public DataGridViewCellLinkedListEnumerator(DataGridViewCellLinkedListElement headElement)
{
this.headElement = headElement;
this.reset = true;
}
///
object IEnumerator.Current
{
get
{
Debug.Assert(this.current != null); // Since this is for internal use only.
return this.current.DataGridViewCell;
}
}
///
bool IEnumerator.MoveNext()
{
if (this.reset)
{
Debug.Assert(this.current == null);
this.current = this.headElement;
this.reset = false;
}
else
{
Debug.Assert(this.current != null); // Since this is for internal use only.
this.current = this.current.Next;
}
return (this.current != null);
}
///
void IEnumerator.Reset()
{
this.reset = true;
this.current = null;
}
}
///
///
/// Represents an element in a linked list.
///
internal class DataGridViewCellLinkedListElement
{
private DataGridViewCell dataGridViewCell;
private DataGridViewCellLinkedListElement next;
///
public DataGridViewCellLinkedListElement(DataGridViewCell dataGridViewCell)
{
Debug.Assert(dataGridViewCell != null);
this.dataGridViewCell = dataGridViewCell;
}
///
public DataGridViewCell DataGridViewCell
{
get
{
return this.dataGridViewCell;
}
}
///
public DataGridViewCellLinkedListElement Next
{
get
{
return this.next;
}
set
{
this.next = value;
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Windows.Forms
{
using System;
using System.Diagnostics;
using System.Collections;
using System.Windows.Forms;
using System.ComponentModel;
///
///
/// Represents a linked list of objects
///
internal class DataGridViewCellLinkedList : IEnumerable
{
private DataGridViewCellLinkedListElement lastAccessedElement;
private DataGridViewCellLinkedListElement headElement;
private int count, lastAccessedIndex;
///
IEnumerator IEnumerable.GetEnumerator()
{
return new DataGridViewCellLinkedListEnumerator(this.headElement);
}
///
public DataGridViewCellLinkedList()
{
this.lastAccessedIndex = -1;
}
///
public DataGridViewCell this[int index]
{
get
{
Debug.Assert(index >= 0);
Debug.Assert(index < this.count);
if (this.lastAccessedIndex == -1 || index < this.lastAccessedIndex)
{
DataGridViewCellLinkedListElement tmp = this.headElement;
int tmpIndex = index;
while (tmpIndex > 0)
{
tmp = tmp.Next;
tmpIndex--;
}
this.lastAccessedElement = tmp;
this.lastAccessedIndex = index;
return tmp.DataGridViewCell;
}
else
{
while (this.lastAccessedIndex < index)
{
this.lastAccessedElement = this.lastAccessedElement.Next;
this.lastAccessedIndex++;
}
return this.lastAccessedElement.DataGridViewCell;
}
}
}
///
public int Count
{
get
{
return this.count;
}
}
///
public DataGridViewCell HeadCell
{
get
{
Debug.Assert(this.headElement != null);
return this.headElement.DataGridViewCell;
}
}
///
public void Add(DataGridViewCell dataGridViewCell)
{
Debug.Assert(dataGridViewCell != null);
Debug.Assert(dataGridViewCell.DataGridView.SelectionMode == DataGridViewSelectionMode.CellSelect ||
dataGridViewCell.DataGridView.SelectionMode == DataGridViewSelectionMode.ColumnHeaderSelect ||
dataGridViewCell.DataGridView.SelectionMode == DataGridViewSelectionMode.RowHeaderSelect);
DataGridViewCellLinkedListElement newHead = new DataGridViewCellLinkedListElement(dataGridViewCell);
if (this.headElement != null)
{
newHead.Next = this.headElement;
}
this.headElement = newHead;
this.count++;
this.lastAccessedElement = null;
this.lastAccessedIndex = -1;
}
///
public void Clear()
{
this.lastAccessedElement = null;
this.lastAccessedIndex = -1;
this.headElement = null;
this.count = 0;
}
///
public bool Contains(DataGridViewCell dataGridViewCell)
{
Debug.Assert(dataGridViewCell != null);
int index = 0;
DataGridViewCellLinkedListElement tmp = this.headElement;
while (tmp != null)
{
if (tmp.DataGridViewCell == dataGridViewCell)
{
this.lastAccessedElement = tmp;
this.lastAccessedIndex = index;
return true;
}
tmp = tmp.Next;
index++;
}
return false;
}
///
public bool Remove(DataGridViewCell dataGridViewCell)
{
Debug.Assert(dataGridViewCell != null);
DataGridViewCellLinkedListElement tmp1 = null, tmp2 = this.headElement;
while (tmp2 != null)
{
if (tmp2.DataGridViewCell == dataGridViewCell)
{
break;
}
tmp1 = tmp2;
tmp2 = tmp2.Next;
}
if (tmp2.DataGridViewCell == dataGridViewCell)
{
DataGridViewCellLinkedListElement tmp3 = tmp2.Next;
if (tmp1 == null)
{
this.headElement = tmp3;
}
else
{
tmp1.Next = tmp3;
}
this.count--;
this.lastAccessedElement = null;
this.lastAccessedIndex = -1;
return true;
}
return false;
}
/* Unused for now
///
public DataGridViewCell RemoveHead()
{
if (this.headElement == null)
{
return null;
}
DataGridViewCellLinkedListElement tmp = this.headElement;
this.headElement = tmp.Next;
this.count--;
this.lastAccessedElement = null;
this.lastAccessedIndex = -1;
return tmp.DataGridViewCell;
}
*/
///
public int RemoveAllCellsAtBand(bool column, int bandIndex)
{
int removedCount = 0;
DataGridViewCellLinkedListElement tmp1 = null, tmp2 = this.headElement;
while (tmp2 != null)
{
if ((column && tmp2.DataGridViewCell.ColumnIndex == bandIndex) ||
(!column && tmp2.DataGridViewCell.RowIndex == bandIndex))
{
DataGridViewCellLinkedListElement tmp3 = tmp2.Next;
if (tmp1 == null)
{
this.headElement = tmp3;
}
else
{
tmp1.Next = tmp3;
}
tmp2 = tmp3;
this.count--;
this.lastAccessedElement = null;
this.lastAccessedIndex = -1;
removedCount++;
}
else
{
tmp1 = tmp2;
tmp2 = tmp2.Next;
}
}
return removedCount;
}
}
///
///
/// Represents an emunerator of elements in a linked list.
///
internal class DataGridViewCellLinkedListEnumerator : IEnumerator
{
private DataGridViewCellLinkedListElement headElement;
private DataGridViewCellLinkedListElement current;
private bool reset;
///
public DataGridViewCellLinkedListEnumerator(DataGridViewCellLinkedListElement headElement)
{
this.headElement = headElement;
this.reset = true;
}
///
object IEnumerator.Current
{
get
{
Debug.Assert(this.current != null); // Since this is for internal use only.
return this.current.DataGridViewCell;
}
}
///
bool IEnumerator.MoveNext()
{
if (this.reset)
{
Debug.Assert(this.current == null);
this.current = this.headElement;
this.reset = false;
}
else
{
Debug.Assert(this.current != null); // Since this is for internal use only.
this.current = this.current.Next;
}
return (this.current != null);
}
///
void IEnumerator.Reset()
{
this.reset = true;
this.current = null;
}
}
///
///
/// Represents an element in a linked list.
///
internal class DataGridViewCellLinkedListElement
{
private DataGridViewCell dataGridViewCell;
private DataGridViewCellLinkedListElement next;
///
public DataGridViewCellLinkedListElement(DataGridViewCell dataGridViewCell)
{
Debug.Assert(dataGridViewCell != null);
this.dataGridViewCell = dataGridViewCell;
}
///
public DataGridViewCell DataGridViewCell
{
get
{
return this.dataGridViewCell;
}
}
///
public DataGridViewCellLinkedListElement Next
{
get
{
return this.next;
}
set
{
this.next = value;
}
}
}
}
// 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
- DoubleStorage.cs
- GB18030Encoding.cs
- DataViewSetting.cs
- EmissiveMaterial.cs
- PageThemeBuildProvider.cs
- RootBrowserWindowAutomationPeer.cs
- XmlCharCheckingReader.cs
- HGlobalSafeHandle.cs
- xamlnodes.cs
- ResourceDescriptionAttribute.cs
- SqlNodeAnnotations.cs
- LocatorGroup.cs
- NavigationWindow.cs
- DBSqlParserColumnCollection.cs
- XmlNodeWriter.cs
- NullToBooleanConverter.cs
- CodeIdentifiers.cs
- WebPart.cs
- PartialList.cs
- SqlBulkCopyColumnMappingCollection.cs
- TCPClient.cs
- KnownTypes.cs
- TextRenderer.cs
- JsonCollectionDataContract.cs
- SimpleWorkerRequest.cs
- Perspective.cs
- DataBinding.cs
- NetworkInformationException.cs
- ServiceModelExtensionElement.cs
- AuthenticationServiceManager.cs
- XmlReflectionImporter.cs
- XmlDictionaryWriter.cs
- ResourceType.cs
- XmlSerializationReader.cs
- BooleanSwitch.cs
- IChannel.cs
- BitmapEffectvisualstate.cs
- ImplicitInputBrush.cs
- TranslateTransform.cs
- QueueProcessor.cs
- BitmapVisualManager.cs
- ScriptReferenceEventArgs.cs
- Number.cs
- NavigationHelper.cs
- XmlComment.cs
- GeneralTransform2DTo3DTo2D.cs
- DesignerHierarchicalDataSourceView.cs
- _NTAuthentication.cs
- OperationResponse.cs
- FrameworkContentElement.cs
- TableRowCollection.cs
- _Win32.cs
- IntellisenseTextBox.cs
- WSDualHttpBindingElement.cs
- Span.cs
- DBAsyncResult.cs
- OutputCacheSettingsSection.cs
- OptimalBreakSession.cs
- TextEditorCharacters.cs
- Stackframe.cs
- DomNameTable.cs
- FunctionDescription.cs
- NumberFunctions.cs
- ComponentEditorForm.cs
- ReflectEventDescriptor.cs
- StorageMappingItemLoader.cs
- PathFigureCollectionValueSerializer.cs
- EntryPointNotFoundException.cs
- baseaxisquery.cs
- arabicshape.cs
- WMIGenerator.cs
- AddingNewEventArgs.cs
- AvTraceFormat.cs
- TagNameToTypeMapper.cs
- TableAdapterManagerHelper.cs
- TraceUtility.cs
- ControlsConfig.cs
- Mutex.cs
- HttpClientChannel.cs
- GatewayIPAddressInformationCollection.cs
- TableLayoutColumnStyleCollection.cs
- PackUriHelper.cs
- WebPartsSection.cs
- WebPartEditorOkVerb.cs
- XPathDescendantIterator.cs
- WsdlBuildProvider.cs
- SevenBitStream.cs
- Calendar.cs
- WindowsGrip.cs
- Rotation3DAnimationBase.cs
- CodeTypeParameter.cs
- ToolStripItemBehavior.cs
- AttributeAction.cs
- FacetChecker.cs
- ConfigurationSectionGroupCollection.cs
- TextRunCache.cs
- XmlKeywords.cs
- SQLCharsStorage.cs
- StyleConverter.cs
- TypeUtils.cs