From 97f4bf5ca52fc89a879a05f4a68b5058f51bb82a Mon Sep 17 00:00:00 2001 From: schoetbi Date: Tue, 30 Apr 2024 13:47:01 +0200 Subject: [PATCH] Bugfixes for 2.0.0 The main difference for this is the change of ContextMenu to ContextMenuStrip. The header context menu now is opened also when clicking on any cell in the table. If this is not desired table.ContextMenuStrip should be set to null - Moved gitversion.yml - Include pdbs in nuget package - create symbol package - Fixed nullref exception in HeaderContextMenu OnOpening in case the model is not set - Avoid duplictate header columns in header context menu --- gitversion.yml | 2 ++ src/XPTable/Models/HeaderContextMenu.cs | 47 +++++++++++++++---------- src/XPTable/Models/Table.cs | 1 + src/XPTable/XPTable.csproj | 5 ++- src/XPTable/gitversion.yml | 1 - 5 files changed, 36 insertions(+), 20 deletions(-) create mode 100644 gitversion.yml delete mode 100644 src/XPTable/gitversion.yml diff --git a/gitversion.yml b/gitversion.yml new file mode 100644 index 0000000..833fa0f --- /dev/null +++ b/gitversion.yml @@ -0,0 +1,2 @@ +next-version: 2.0.0 +mode: ContinuousDeployment \ No newline at end of file diff --git a/src/XPTable/Models/HeaderContextMenu.cs b/src/XPTable/Models/HeaderContextMenu.cs index 5cfe7bf..ce26e87 100644 --- a/src/XPTable/Models/HeaderContextMenu.cs +++ b/src/XPTable/Models/HeaderContextMenu.cs @@ -35,6 +35,9 @@ namespace XPTable.Models { + using System.Data.Common; + using System.Linq; + /// /// A specialized ContextMenu for Column Headers /// @@ -150,27 +153,34 @@ internal bool Enabled protected override void OnOpening(CancelEventArgs e) { - if (model.Columns.Count > 0) + if (Items.Count == 0 && model?.Columns != null) { - ToolStripMenuItem item; - - for (var i = 0; i < model.Columns.Count; i++) + foreach (var column in model.Columns.OfType().Take(9)) { - if (i == 10) + var item = new ToolStripMenuItem(column.Text) { - Items.Add(separator); - Items.Add(moreMenuItem); - - break; - } - - // TODO MenuItem is no longer supported. Use ToolStripMenuItem instead. For more details see https://docs.microsoft.com/en-us/dotnet/core/compatibility/winforms#removed-controls - item = new ToolStripMenuItem(model.Columns[i].Text); + Tag = column + }; item.Click += menuItem_Click; - item.Checked = model.Columns[i].Visible; - + item.Checked = column.Visible; Items.Add(item); } + + if (model.Columns.Count > 9) + { + Items.Add(separator); + Items.Add(moreMenuItem); + } + } + else + { + foreach (var item in Items.OfType()) + { + if (item.Tag is Column column) + { + item.Checked = column.Visible; + } + } } base.OnOpening(e); @@ -184,11 +194,12 @@ protected override void OnOpening(CancelEventArgs e) private void menuItem_Click(object sender, EventArgs e) { var item = (ToolStripMenuItem)sender; - - model.Columns[item.MergeIndex].Visible = !item.Checked; + if (item.Tag is Column column) + { + column.Visible = !item.Checked; + } } - /// /// /// diff --git a/src/XPTable/Models/Table.cs b/src/XPTable/Models/Table.cs index 50e0085..9b538a5 100644 --- a/src/XPTable/Models/Table.cs +++ b/src/XPTable/Models/Table.cs @@ -931,6 +931,7 @@ public Table() beginUpdateCount = 0; init = false; preview = false; + ContextMenuStrip = headerContextMenu; } #endregion diff --git a/src/XPTable/XPTable.csproj b/src/XPTable/XPTable.csproj index 7c4d4e7..d32b942 100644 --- a/src/XPTable/XPTable.csproj +++ b/src/XPTable/XPTable.csproj @@ -17,6 +17,7 @@ true false true + true true @@ -81,7 +82,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -92,6 +93,8 @@ + true + snupkg XPTable A fully customizable ListView style control based on Java's JTable diff --git a/src/XPTable/gitversion.yml b/src/XPTable/gitversion.yml deleted file mode 100644 index ddba28c..0000000 --- a/src/XPTable/gitversion.yml +++ /dev/null @@ -1 +0,0 @@ -next-version: 2.0.0 \ No newline at end of file