浏览代码

Add table example check to prevent crashes (#2691)

Co-authored-by: Tig <[email protected]>
Maciej 2 年之前
父节点
当前提交
7936dd1e85
共有 1 个文件被更改,包括 9 次插入0 次删除
  1. 9 0
      UICatalog/Scenarios/TableEditor.cs

+ 9 - 0
UICatalog/Scenarios/TableEditor.cs

@@ -250,6 +250,11 @@ namespace UICatalog.Scenarios {
 
 		private void SetMinAcceptableWidthToOne ()
 		{
+			var columns = tableView?.Table?.Columns;
+			if (columns is null) {
+				MessageBox.ErrorQuery ("No Table", "No table is currently loaded", "Ok");
+				return;
+			}
 			foreach (DataColumn c in tableView.Table.Columns) 
 			{
 				var style = tableView.Style.GetOrCreateColumnStyle (c);
@@ -276,6 +281,10 @@ namespace UICatalog.Scenarios {
 
 		private void RunColumnWidthDialog (DataColumn col, string prompt, Action<ColumnStyle,int> setter,Func<ColumnStyle,int> getter)
 		{
+			if (col is null) {
+				MessageBox.ErrorQuery ("No Table", "No table is currently loaded", "Ok");
+				return;
+			}
 			var accepted = false;
 			var ok = new Button ("Ok", is_default: true);
 			ok.Clicked += () => { accepted = true; Application.RequestStop (); };