Skip to content

Commit 0b2bb21

Browse files
author
grammarian
committed
- Added bounds check to GetNthObject()
- Fix spelling mistakes git-svn-id: https://svn.code.sf.net/p/objectlistview/code/cs/trunk@815 0bec5ed8-b53f-49e6-9885-ce7bc93af311
1 parent 9201cbd commit 0b2bb21

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

ObjectListView/TreeListView.cs

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* Date: 23/09/2008 11:15 AM
66
*
77
* Change log:
8+
* v2.9.2
9+
* 2016-06-02 JPP - Added bounds check to GetNthObject().
810
* v2.9
911
* 2015-08-02 JPP - Fixed buy with hierarchical checkboxes where setting the checkedness of a deeply
1012
* nested object would sometimes not correctly calculate the changes in the hierarchy. SF #150.
@@ -39,7 +41,7 @@
3941
* If some children are checked and some are not, the parent is indeterminate.
4042
* v2.6
4143
* 2012-10-25 JPP - Circumvent annoying issue in ListView control where changing
42-
* selection would leave artifacts on the control.
44+
* selection would leave artefacts on the control.
4345
* 2012-08-10 JPP - Don't trigger selection changed events during expands
4446
*
4547
* v2.5.1
@@ -396,7 +398,7 @@ public override IEnumerable ObjectsForClustering {
396398

397399
/// <summary>
398400
/// After expanding a branch, should the TreeListView attempts to show as much of the
399-
/// revealed descendents as possible.
401+
/// revealed descendants as possible.
400402
/// </summary>
401403
[Category("ObjectListView"),
402404
Description("Should the parent of an expand subtree be scrolled to the top revealing the children?"),
@@ -633,9 +635,9 @@ public virtual void Expand(Object model) {
633635
try {
634636
int countPerPage = NativeMethods.GetCountPerPage(this);
635637
int descedentCount = this.TreeModel.GetVisibleDescendentCount(model);
636-
// If all of the descendents can be shown in the window, make sure that last one is visible.
637-
// If all the descendents can't fit into the window, move the model to the top of the window
638-
// (which will show as many of the descendents as possible)
638+
// If all of the descendants can be shown in the window, make sure that last one is visible.
639+
// If all the descendants can't fit into the window, move the model to the top of the window
640+
// (which will show as many of the descendants as possible)
639641
if (descedentCount < countPerPage) {
640642
this.EnsureVisible(index + descedentCount);
641643
} else {
@@ -994,7 +996,7 @@ public override OLVListItem MakeListViewItem(int itemIndex) {
994996
}
995997

996998
/// <summary>
997-
/// Reinitialize the Tree structure
999+
/// Reinitialise the Tree structure
9981000
/// </summary>
9991001
protected virtual void RegenerateTree() {
10001002
this.TreeModel = this.TreeFactory == null ? new Tree(this) : this.TreeFactory(this);
@@ -1339,7 +1341,7 @@ public virtual int Collapse(Object model) {
13391341
int count = br.NumberVisibleDescendents;
13401342
br.Collapse();
13411343

1342-
// Remove the visible descendents from after the branch itself
1344+
// Remove the visible descendants from after the branch itself
13431345
int index = this.GetObjectIndex(model);
13441346
this.objectList.RemoveRange(index + 1, count);
13451347
this.RebuildObjectMap(0);
@@ -1408,10 +1410,10 @@ public virtual Branch GetBranch(object model) {
14081410
}
14091411

14101412
/// <summary>
1411-
/// Return the number of visible descendents that are below the given model.
1413+
/// Return the number of visible descendants that are below the given model.
14121414
/// </summary>
14131415
/// <param name="model">The model whose descendent count is to be returned</param>
1414-
/// <returns>The number of visible descendents. 0 if the model doesn't exist or is collapsed</returns>
1416+
/// <returns>The number of visible descendants. 0 if the model doesn't exist or is collapsed</returns>
14151417
public virtual int GetVisibleDescendentCount(object model)
14161418
{
14171419
Branch br = this.GetBranch(model);
@@ -1430,7 +1432,7 @@ public virtual int RebuildChildren(Object model) {
14301432

14311433
int count = br.NumberVisibleDescendents;
14321434

1433-
// Remove the visible descendents from after the branch itself
1435+
// Remove the visible descendants from after the branch itself
14341436
int index = this.GetObjectIndex(model);
14351437
if (count > 0)
14361438
this.objectList.RemoveRange(index + 1, count);
@@ -1489,7 +1491,7 @@ protected virtual void InsertChildren(Branch br, int index) {
14891491
br.Expand();
14901492
br.Sort(this.GetBranchComparer());
14911493

1492-
// Insert the branch's visible descendents after the branch itself
1494+
// Insert the branch's visible descendants after the branch itself
14931495
this.objectList.InsertRange(index, br.Flatten());
14941496
this.RebuildObjectMap(index);
14951497
}
@@ -1543,7 +1545,9 @@ internal Branch MakeBranch(Branch parent, object model) {
15431545
/// <param name="n"></param>
15441546
/// <returns></returns>
15451547
public virtual object GetNthObject(int n) {
1546-
return this.objectList[n];
1548+
if (n >= 0 && n < this.objectList.Count)
1549+
return this.objectList[n];
1550+
return null;
15471551
}
15481552

15491553
/// <summary>
@@ -1975,7 +1979,7 @@ public Object Model {
19751979
private Object model;
19761980

19771981
/// <summary>
1978-
/// Return the number of descendents of this branch that are currently visible
1982+
/// Return the number of descendants of this branch that are currently visible
19791983
/// </summary>
19801984
/// <returns></returns>
19811985
public virtual int NumberVisibleDescendents {
@@ -2104,7 +2108,7 @@ public virtual void FetchChildren() {
21042108
}
21052109

21062110
/// <summary>
2107-
/// Collapse the visible descendents of this branch into list of model objects
2111+
/// Collapse the visible descendants of this branch into list of model objects
21082112
/// </summary>
21092113
/// <returns></returns>
21102114
public virtual IList Flatten() {
@@ -2115,7 +2119,7 @@ public virtual IList Flatten() {
21152119
}
21162120

21172121
/// <summary>
2118-
/// Flatten this branch's visible descendents onto the given list.
2122+
/// Flatten this branch's visible descendants onto the given list.
21192123
/// </summary>
21202124
/// <param name="flatList"></param>
21212125
/// <remarks>The branch itself is <b>not</b> included in the list.</remarks>
@@ -2152,7 +2156,7 @@ public virtual void RefreshChildren() {
21522156
}
21532157

21542158
/// <summary>
2155-
/// Sort the sub-branches and their descendents so they are ordered according
2159+
/// Sort the sub-branches and their descendants so they are ordered according
21562160
/// to the given comparer.
21572161
/// </summary>
21582162
/// <param name="comparer">The comparer that orders the branches</param>

0 commit comments

Comments
 (0)