Skip to content

Commit

Permalink
[BUG] Fix DataGridView Default Error is shown + NullReferenceException (
Browse files Browse the repository at this point in the history
#139), version 1.0.16.2
  • Loading branch information
Hofknecht committed Oct 10, 2020
1 parent a2f697a commit 808ab53
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 21 deletions.
55 changes: 36 additions & 19 deletions Business/Menus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ internal class Menus : IDisposable
private RowData loadingRowData = null;
private bool showingMessageBox = false;
private TaskbarPosition taskbarPosition = new WindowsTaskbar().Position;
private bool searchTextChanging = false;

public Menus()
{
Expand Down Expand Up @@ -484,25 +485,28 @@ internal void DisposeMenu(Menu menuToDispose)
menuToDispose.CmdKeyProcessed -= keyboardInput.CmdKeyProcessed;
menuToDispose.SearchTextChanging -= keyboardInput.SearchTextChanging;
menuToDispose.SearchTextChanged -= Menu_SearchTextChanged;
DataGridView dgv = menuToDispose.GetDataGridView();
dgv.CellMouseEnter -= dgvMouseRow.CellMouseEnter;
dgv.CellMouseLeave -= dgvMouseRow.CellMouseLeave;
dgv.MouseLeave -= dgvMouseRow.MouseLeave;
dgv.MouseMove -= waitToOpenMenu.MouseMove;
dgv.MouseDown -= Dgv_MouseDown;
dgv.MouseDoubleClick -= Dgv_MouseDoubleClick;
dgv.SelectionChanged -= Dgv_SelectionChanged;
dgv.RowPostPaint -= Dgv_RowPostPaint;
dgv.ClearSelection();

foreach (DataGridViewRow row in dgv.Rows)
{
RowData rowData = (RowData)row.Cells[2].Value;
rowData.Dispose();
DisposeMenu(rowData.SubMenu);
DataGridView dgv = menuToDispose?.GetDataGridView();
if (dgv != null)
{
dgv.CellMouseEnter -= dgvMouseRow.CellMouseEnter;
dgv.CellMouseLeave -= dgvMouseRow.CellMouseLeave;
dgv.MouseLeave -= dgvMouseRow.MouseLeave;
dgv.MouseMove -= waitToOpenMenu.MouseMove;
dgv.MouseDown -= Dgv_MouseDown;
dgv.MouseDoubleClick -= Dgv_MouseDoubleClick;
dgv.SelectionChanged -= Dgv_SelectionChanged;
dgv.RowPostPaint -= Dgv_RowPostPaint;
dgv.ClearSelection();

foreach (DataGridViewRow row in dgv.Rows)
{
RowData rowData = (RowData)row.Cells[2].Value;
rowData?.Dispose();
DisposeMenu(rowData.SubMenu);
}
}

menuToDispose.Dispose();
menuToDispose?.Dispose();
}
}

Expand Down Expand Up @@ -613,7 +617,7 @@ private Menu Create(MenuData menuData, string title = null)
menu.MouseEnter += waitLeave.Stop;
menu.KeyPress += keyboardInput.KeyPress;
menu.CmdKeyProcessed += keyboardInput.CmdKeyProcessed;
menu.SearchTextChanging += keyboardInput.SearchTextChanging;
menu.SearchTextChanging += Menu_SearchTextChanging;
menu.SearchTextChanged += Menu_SearchTextChanged;
menu.Deactivate += Deactivate;
void Deactivate(object sender, EventArgs e)
Expand Down Expand Up @@ -719,6 +723,7 @@ private void Dgv_SelectionChanged(object sender, EventArgs e)

private void RefreshSelection(DataGridView dgv)
{
dgv.SelectionChanged -= Dgv_SelectionChanged;
foreach (DataGridViewRow row in dgv.Rows)
{
RowData rowData = (RowData)row.Cells[2].Value;
Expand Down Expand Up @@ -752,7 +757,12 @@ private void RefreshSelection(DataGridView dgv)
}
}

dgv.Refresh();
dgv.SelectionChanged += Dgv_SelectionChanged;

if (!searchTextChanging)
{
dgv.Refresh();
}
}

private void Dgv_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
Expand Down Expand Up @@ -921,10 +931,17 @@ private void AdjustMenusSizeAndLocation()
}
}

private void Menu_SearchTextChanging()
{
searchTextChanging = true;
keyboardInput.SearchTextChanging();
}

private void Menu_SearchTextChanged(object sender, EventArgs e)
{
keyboardInput.SearchTextChanged(sender, e);
AdjustMenusSizeAndLocation();
searchTextChanging = false;
}
}
}
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.16.1")]
[assembly: AssemblyFileVersion("1.0.16.1")]
[assembly: AssemblyVersion("1.0.16.2")]
[assembly: AssemblyFileVersion("1.0.16.2")]

0 comments on commit 808ab53

Please sign in to comment.