Browse Source

Add table example check to prevent crashes (#2691)

Co-authored-by: Tig <[email protected]>
Maciej 2 years ago
parent
commit
7936dd1e85
1 changed files with 9 additions and 0 deletions
  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 (); };