Skip to content

Commit

Permalink
Merge pull request #24 from DeltaJordan/master
Browse files Browse the repository at this point in the history
Add Context Menu to Distribution Tables to Enable/Disable Entries When Using Uniform Mode
  • Loading branch information
Nifyr authored Feb 2, 2024
2 parents 58280e2 + b3d20fc commit 90c0e7e
Showing 1 changed file with 79 additions and 0 deletions.
79 changes: 79 additions & 0 deletions Forms/ItemDistributionForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
Expand All @@ -27,6 +28,84 @@ public ItemDistributionForm(MainForm.ItemDistributionControl idc)
RefreshDistributionDisplay();

distributionSelectComboBox.SelectedIndexChanged += SelectedDistributionChanged;

ContextMenuStrip ctxDataGrid = new();
ctxDataGrid.Opening += CtxDataGrid_Opening;

ToolStripMenuItem btnCheckSelected = new("Check Selected");
btnCheckSelected.Click += BtnCheckSelected_Click;
ctxDataGrid.Items.Add(btnCheckSelected);

ToolStripMenuItem btnUncheckSelected = new("Uncheck Selected");
btnUncheckSelected.Click += BtnUncheckSelected_Click;
ctxDataGrid.Items.Add(btnUncheckSelected);

ToolStripMenuItem btnToggleSelected = new("Toggle Selected");
btnToggleSelected.Click += BtnToggleSelected_Click;
ctxDataGrid.Items.Add(btnToggleSelected);

dataGridView1.ContextMenuStrip = ctxDataGrid;
}

private void CtxDataGrid_Opening(object sender, CancelEventArgs e)
{
foreach (var cell in dataGridView1.SelectedCells)
{
if (cell is DataGridViewCheckBoxCell)
{
e.Cancel = false;
return;
}
}

e.Cancel = true;
}

private void BtnToggleSelected_Click(object sender, EventArgs e)
{
foreach (var cell in dataGridView1.SelectedCells)
{
if (cell is DataGridViewCheckBoxCell checkBoxCell)
{
if (checkBoxCell.Value is bool isChecked)
{
checkBoxCell.Value = !isChecked;
}
else
{
// This checkbox has a default value (for some reason)
checkBoxCell.Value = true;
}
}
}

dataGridView1.EndEdit();
}

private void BtnUncheckSelected_Click(object sender, EventArgs e)
{
foreach (var cell in dataGridView1.SelectedCells)
{
if (cell is DataGridViewCheckBoxCell checkBoxCell)
{
checkBoxCell.Value = false;
}
}

dataGridView1.EndEdit();
}

private void BtnCheckSelected_Click(object sender, EventArgs e)
{
foreach (var cell in dataGridView1.SelectedCells)
{
if (cell is DataGridViewCheckBoxCell checkBoxCell)
{
checkBoxCell.Value = true;
}
}

dataGridView1.EndEdit();
}

private void SelectedDistributionChanged(object sender, EventArgs e)
Expand Down

0 comments on commit 90c0e7e

Please sign in to comment.