瀏覽代碼

Merge pull request #735 from daltskin/master

ListView - handle null values
Charlie Kindel 5 年之前
父節點
當前提交
b13de5435b
共有 1 個文件被更改,包括 7 次插入5 次删除
  1. 7 5
      Terminal.Gui/Views/ListView.cs

+ 7 - 5
Terminal.Gui/Views/ListView.cs

@@ -589,15 +589,17 @@ namespace Terminal.Gui {
 		/// <param name="source"></param>
 		public ListWrapper (IList source)
 		{
-			count = source.Count;
-			marks = new BitArray (count);
-			this.src = source;
+			if (source != null) {
+				count = source.Count;
+				marks = new BitArray (count);
+				this.src = source;
+			}
 		}
 
 		/// <summary>
 		/// Gets the number of items in the <see cref="IList"/>.
 		/// </summary>
-		public int Count => src.Count;
+		public int Count => src != null ? src.Count : 0;
 
 		void RenderUstr (ConsoleDriver driver, ustring ustr, int col, int line, int width)
 		{
@@ -632,7 +634,7 @@ namespace Terminal.Gui {
 			container.Move (col, line);
 			var t = src [item];
 			if (t == null) {
-				RenderUstr (driver, ustring.Make(""), col, line, width);
+				RenderUstr (driver, ustring.Make (""), col, line, width);
 			} else {
 				if (t is ustring) {
 					RenderUstr (driver, (ustring)t, col, line, width);