Add setting to persist ProductsGrid column widths
This commit is contained in:
parent
cfe2eac351
commit
30feb42ed8
@ -127,13 +127,13 @@ namespace AppScaffolding
|
||||
config.AutoScan = true;
|
||||
|
||||
if (!config.Exists(nameof(config.HiddenGridColumns)))
|
||||
config.HiddenGridColumns = Array.Empty<string>();
|
||||
config.HiddenGridColumns = new Dictionary<string, bool>();
|
||||
|
||||
if (!config.Exists(nameof(config.GridColumnsDisplayIndices)))
|
||||
{
|
||||
int startIndex = 0;
|
||||
config.GridColumnsDisplayIndices = new int[30].Select(_ => startIndex++).ToArray();
|
||||
}
|
||||
config.GridColumnsDisplayIndices = new Dictionary<string, int>();
|
||||
|
||||
if (!config.Exists(nameof(config.GridColumnsWidths)))
|
||||
config.GridColumnsWidths = new Dictionary<string, int>();
|
||||
}
|
||||
|
||||
/// <summary>Initialize logging. Run after migration</summary>
|
||||
|
||||
@ -52,7 +52,6 @@ namespace FileManager
|
||||
if (obj is null) return default;
|
||||
if (obj is JValue jValue) return jValue.Value<T>();
|
||||
if (obj is JObject jObject) return jObject.ToObject<T>();
|
||||
if (obj is JArray jArray && typeof(T).IsArray) return jArray.ToObject<T>();
|
||||
return (T)obj;
|
||||
}
|
||||
|
||||
|
||||
@ -180,20 +180,27 @@ namespace LibationFileManager
|
||||
set => persistentDictionary.SetNonString(nameof(LameVBRQuality), value);
|
||||
}
|
||||
|
||||
[Description("A list of GridView data property names whose columns should be hidden in ProductsGrid")]
|
||||
public string[] HiddenGridColumns
|
||||
[Description("A Dictionary of GridView data property names and bool indicating its column's visibility in ProductsGrid")]
|
||||
public Dictionary<string, bool> HiddenGridColumns
|
||||
{
|
||||
get => persistentDictionary.GetNonString<string[]>(nameof(HiddenGridColumns));
|
||||
get => persistentDictionary.GetNonString<Dictionary<string, bool>>(nameof(HiddenGridColumns));
|
||||
set => persistentDictionary.SetNonString(nameof(HiddenGridColumns), value);
|
||||
}
|
||||
|
||||
[Description("A DisplayIndex list of columns in ProductsGrid")]
|
||||
public int[] GridColumnsDisplayIndices
|
||||
[Description("A Dictionary of GridView data property names and int indicating its column's display index in ProductsGrid")]
|
||||
public Dictionary<string, int> GridColumnsDisplayIndices
|
||||
{
|
||||
get => persistentDictionary.GetNonString<int[]>(nameof(GridColumnsDisplayIndices));
|
||||
get => persistentDictionary.GetNonString<Dictionary<string,int>>(nameof(GridColumnsDisplayIndices));
|
||||
set => persistentDictionary.SetNonString(nameof(GridColumnsDisplayIndices), value);
|
||||
}
|
||||
|
||||
[Description("A Dictionary of GridView data property names and int indicating its column's width in ProductsGrid")]
|
||||
public Dictionary<string, int> GridColumnsWidths
|
||||
{
|
||||
get => persistentDictionary.GetNonString<Dictionary<string,int>>(nameof(GridColumnsWidths));
|
||||
set => persistentDictionary.SetNonString(nameof(GridColumnsWidths), value);
|
||||
}
|
||||
|
||||
public enum BadBookAction
|
||||
{
|
||||
[Description("Ask each time what action to take.")]
|
||||
|
||||
@ -98,6 +98,7 @@
|
||||
this.gridEntryDataGridView.Size = new System.Drawing.Size(1510, 380);
|
||||
this.gridEntryDataGridView.TabIndex = 0;
|
||||
this.gridEntryDataGridView.ColumnDisplayIndexChanged += new System.Windows.Forms.DataGridViewColumnEventHandler(this.gridEntryDataGridView_ColumnDisplayIndexChanged);
|
||||
this.gridEntryDataGridView.ColumnWidthChanged += new System.Windows.Forms.DataGridViewColumnEventHandler(this.gridEntryDataGridView_ColumnWidthChanged);
|
||||
//
|
||||
// dataGridViewImageButtonBoxColumn1
|
||||
//
|
||||
|
||||
@ -238,16 +238,16 @@ namespace LibationWinForms
|
||||
|
||||
//Restore Grid Display Settings
|
||||
var config = Configuration.Instance;
|
||||
var displayIndices = config.GridColumnsDisplayIndices;
|
||||
var hiddenGridColumns = config.HiddenGridColumns;
|
||||
var displayIndices = config.GridColumnsDisplayIndices;
|
||||
var gridColumnsWidths = config.GridColumnsWidths;
|
||||
|
||||
var cmsKiller = new ContextMenuStrip();
|
||||
|
||||
int columnIndex = 0;
|
||||
foreach (DataGridViewColumn column in _dataGridView.Columns)
|
||||
{
|
||||
var visible = !hiddenGridColumns.Contains(column.DataPropertyName);
|
||||
var itemName = column.DataPropertyName;
|
||||
var visible = !hiddenGridColumns.GetValueOrDefault(itemName, false);
|
||||
|
||||
var menuItem = new ToolStripMenuItem()
|
||||
{
|
||||
@ -259,7 +259,9 @@ namespace LibationWinForms
|
||||
contextMenuStrip1.Items.Add(menuItem);
|
||||
|
||||
column.Visible = visible;
|
||||
column.DisplayIndex = displayIndices[columnIndex++];
|
||||
column.DisplayIndex = displayIndices.GetValueOrDefault(itemName, column.Index);
|
||||
column.Width = gridColumnsWidths.GetValueOrDefault(itemName, column.Width);
|
||||
column.MinimumWidth = 10;
|
||||
column.HeaderCell.ContextMenuStrip = contextMenuStrip1;
|
||||
|
||||
//Setting a default ContextMenuStrip will allow the columns to handle the
|
||||
@ -272,6 +274,24 @@ namespace LibationWinForms
|
||||
base.OnVisibleChanged(e);
|
||||
}
|
||||
|
||||
private void gridEntryDataGridView_ColumnDisplayIndexChanged(object sender, DataGridViewColumnEventArgs e)
|
||||
{
|
||||
var config = Configuration.Instance;
|
||||
|
||||
var dictionary = config.GridColumnsDisplayIndices;
|
||||
dictionary[e.Column.DataPropertyName] = e.Column.DisplayIndex;
|
||||
config.GridColumnsDisplayIndices = dictionary;
|
||||
}
|
||||
|
||||
private void gridEntryDataGridView_ColumnWidthChanged(object sender, DataGridViewColumnEventArgs e)
|
||||
{
|
||||
var config = Configuration.Instance;
|
||||
|
||||
var dictionary = config.GridColumnsWidths;
|
||||
dictionary[e.Column.DataPropertyName] = e.Column.Width;
|
||||
config.GridColumnsWidths = dictionary;
|
||||
}
|
||||
|
||||
private void HideMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var menuItem = sender as ToolStripMenuItem;
|
||||
@ -287,32 +307,14 @@ namespace LibationWinForms
|
||||
menuItem.Checked = !visible;
|
||||
column.Visible = !visible;
|
||||
|
||||
Configuration.Instance.HiddenGridColumns =
|
||||
_dataGridView.Columns
|
||||
.Cast<DataGridViewColumn>()
|
||||
.Where(c => !c.Visible)
|
||||
.Select(c => c.DataPropertyName)
|
||||
.ToArray();
|
||||
}
|
||||
}
|
||||
var config = Configuration.Instance;
|
||||
|
||||
private void gridEntryDataGridView_ColumnDisplayIndexChanged(object sender, DataGridViewColumnEventArgs e)
|
||||
{
|
||||
Configuration.Instance.GridColumnsDisplayIndices
|
||||
= _dataGridView.Columns
|
||||
.Cast<DataGridViewColumn>()
|
||||
.Select(c => c.DisplayIndex)
|
||||
.ToArray();
|
||||
var dictionary = config.HiddenGridColumns;
|
||||
dictionary[propertyName] = visible;
|
||||
config.HiddenGridColumns = dictionary;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
class ContextMenuStripEx : ContextMenuStrip
|
||||
{
|
||||
protected override ToolStripItem CreateDefaultItem(string text, Image image, EventHandler onClick)
|
||||
{
|
||||
return base.CreateDefaultItem(text, image, onClick);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user