From c3c847516361623ff2d37f9d1b42c0c426e97b99 Mon Sep 17 00:00:00 2001 From: Bob Long Date: Wed, 18 Sep 2024 06:47:53 +1000 Subject: [PATCH] ConfigRawParams: Various bugfixes (#3246) * MyDataGridView: enable double-buffering Fixes serious graphical corruption that can happen sometimes when scrolling * ConfigRawParams: fix off-by-one error Additional options like the dropdown box or bitmask button would not show up for the first row * ConfigRawParams: prevent favorites from changing the tree --- Controls/MyDataGridView.cs | 4 +++ GCSViews/ConfigurationView/ConfigRawParams.cs | 26 ++++++++++++++----- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/Controls/MyDataGridView.cs b/Controls/MyDataGridView.cs index 4bd9e0e908..681e4c1df9 100644 --- a/Controls/MyDataGridView.cs +++ b/Controls/MyDataGridView.cs @@ -6,6 +6,10 @@ namespace MissionPlanner.Controls { public class MyDataGridView : DataGridView { + public MyDataGridView() : base() + { + this.DoubleBuffered = true; + } protected override void OnPaint(PaintEventArgs e) { // mono bug - when deleting all rows, the sharedrow no longer exists and throws System.ArgumentOutOfRangeException diff --git a/GCSViews/ConfigurationView/ConfigRawParams.cs b/GCSViews/ConfigurationView/ConfigRawParams.cs index 279891110e..4005026afb 100644 --- a/GCSViews/ConfigurationView/ConfigRawParams.cs +++ b/GCSViews/ConfigurationView/ConfigRawParams.cs @@ -644,10 +644,24 @@ private void BuildTree() treeView1.Nodes.Clear(); var currentNode = treeView1.Nodes.Add("All"); string currentPrefix = ""; - DataGridViewRowCollection rows = Params.Rows; - for (int i = 0; i < rows.Count; i++) + + // Get command names from the gridview + List commands = new List(); + foreach (DataGridViewRow row in Params.Rows) + { + string command = row.Cells[Command.Index].Value.ToString(); + if (!commands.Contains(command)) + { + commands.Add(command); + } + } + + // Sort them again (because of the favorites, they may be out of order) + commands.Sort(); + + for (int i = 0; i < commands.Count; i++) { - string param = rows[i].Cells[Command.Index].Value.ToString(); + string param = commands[i]; // While param does not start with currentPrefix, step up a layer in the tree while (!param.StartsWith(currentPrefix)) @@ -657,13 +671,13 @@ private void BuildTree() } // If this is the last parameter, add it - if (i == rows.Count - 1) + if (i == commands.Count - 1) { currentNode.Nodes.Add(param); break; } - string next_param = rows[i + 1].Cells[Command.Index].Value.ToString(); + string next_param = commands[i + 1]; // While the next parameter has a common prefix with this, add branch nodes string nodeToAdd = param.Substring(currentPrefix.Length).Split('_')[0] + "_"; while (nodeToAdd.Length > 1 // While the currentPrefix is smaller than param @@ -1002,7 +1016,7 @@ private void but_collapse_Click(object sender, EventArgs e) // Create and place the relevant control in the options column when a row is entered private void Params_RowEnter(object sender, DataGridViewCellEventArgs e) { - if (e.RowIndex < 1) + if (e.RowIndex < 0) return; if (optionsControl != null)