Skip to content

Commit

Permalink
fixed colums trailing off the window, added large bool cells, tables …
Browse files Browse the repository at this point in the history
…are now colored by depth
  • Loading branch information
alex committed Apr 5, 2024
1 parent fd516ba commit 14b251e
Show file tree
Hide file tree
Showing 31 changed files with 235 additions and 56 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified MDB/.vs/MDB/v17/.suo
Binary file not shown.
Binary file modified MDB/.vs/MDB/v17/HierarchyCache.v1.txt
Binary file not shown.
Binary file modified MDB/CustomTabControl/JacksonSoft.CustomTabControl.dll
Binary file not shown.
Binary file modified MDB/CustomTabControl/JacksonSoft.CustomTabControl.pdb
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
5 changes: 4 additions & 1 deletion MDB/WindowsFormsApp1/ColorThemes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ public static class ColorThemes
{"FormBack",darkFormBackColor },
{"FormFore",darkFormForeColor },
{"LabelFore",darkLabelColor },
{"DepthColorShift",10 },
{"GridColor",darkGridColor },
{"Disabled",darkDisabledCell },
{"DisabledText",darkDisabledText },
Expand All @@ -285,7 +286,7 @@ public static class ColorThemes
{ "InvalidCellOutline",darkInvalidCellOutline},
{"TabStyle", System.Windows.Forms.TabStyle.ManorDB },
{"TabTextColor", darkTabText},

{"SelectedTabTextColor", darkTabSelectedText},
{"SubTableCellFore",darkSubTableCellText },
{"SubTableSelectedCellFore",darkSubTableSelectedCellText },

Expand All @@ -312,6 +313,7 @@ public static class ColorThemes
{"FormBack",lightFormBackColor },
{"FormFore",lightFormForeColor },
{"LabelFore",lightLabelColor },
{"DepthColorShift",-10 },
{"GridColor",lightGridColor },
{"Disabled",lightDisabledCell },
{"DisabledText",lightDisabledText },
Expand All @@ -323,6 +325,7 @@ public static class ColorThemes
{ "InvalidCellOutline",lightInvalidCellOutline},
{"TabStyle", System.Windows.Forms.TabStyle.VisualStudio },
{"TabTextColor", lightTabText},
{"SelectedTabTextColor", lightTabSelectedText},

{"SubTableCellFore",lightSubTableCellText },
{"SubTableSelectedCellFore",lightSubTableSelectedCellText },
Expand Down
4 changes: 2 additions & 2 deletions MDB/WindowsFormsApp1/ColumnTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static class ColumnTypes
//it stores links to this maintable's primary keys.
{"Foreign Key Refrence",typeof(DataGridViewComboBoxColumn) },
//stores true or false values
{"Bool",typeof(DataGridViewCheckBoxColumn) },
{"Bool",typeof(CustomDataGridViewCheckBoxColumn) },
//this column exists in a subtable and is set to a parent directory layer in the same table upon creation
//it stores links to this parent subtable's primary key's
{"Parent Subtable Foreign Key Refrence",typeof(DataGridViewComboBoxColumn) },
Expand Down Expand Up @@ -121,7 +121,7 @@ internal static dynamic GetDefaultColumnValue(string colType)
}


internal static DataGridViewCheckBoxCell setBoolCellTFVals(DataGridViewCheckBoxCell cell)
internal static CustomDataGridViewCheckBoxCell setBoolCellTFVals(CustomDataGridViewCheckBoxCell cell)
{
cell.FalseValue = false;
cell.TrueValue = true;
Expand Down
107 changes: 107 additions & 0 deletions MDB/WindowsFormsApp1/Custom Controls/CustomDataGridViewCheckBoxCell.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
using System.Drawing;
using System;
using System.Windows.Forms;

namespace MDB
{
public class CustomDataGridViewCheckBoxCell : DataGridViewCheckBoxCell
{
private Rectangle curCellBounds;
private Rectangle checkBoxRect;

public CustomDataGridViewCheckBoxCell() : base() { }

protected override void Paint(
Graphics g,
Rectangle clipBounds,
Rectangle cellBounds,
int rowIndex,
DataGridViewElementStates elementState,
object value,
object formattedValue,
string errorText,
DataGridViewCellStyle cellStyle,
DataGridViewAdvancedBorderStyle advancedBorderStyle,
DataGridViewPaintParts paintParts)
{
// Paint default except the check box parts.
var parts = paintParts & ~(DataGridViewPaintParts.ContentForeground
| DataGridViewPaintParts.ContentBackground);

base.Paint(g,
clipBounds,
cellBounds,
rowIndex,
elementState,
value,
formattedValue,
errorText,
cellStyle,
advancedBorderStyle,
parts);

if (curCellBounds != cellBounds)
{
// To get the box size...
var col = OwningColumn as CustomDataGridViewCheckBoxColumn;

curCellBounds = cellBounds;
// ToDo: Use col.DefaultCellStyle.Alignment or
// DataGridView.ColumnHeadersDefaultCellStyle.Alignment
// to position the box. MiddleCenter here...
checkBoxRect = new Rectangle(
(cellBounds.Width - col.CheckBoxSize.Width) / 2 + cellBounds.X,
(cellBounds.Height - col.CheckBoxSize.Height) / 2 + cellBounds.Y,
col.CheckBoxSize.Width,
col.CheckBoxSize.Height);
}

ControlPaint.DrawCheckBox(g, checkBoxRect, (bool)formattedValue
? ButtonState.Checked | ButtonState.Flat
: ButtonState.Flat);
}

// In case you don't use the `Alignment` property to position the
// box. This is to disallow toggling the state if you click on the
// original content area outside the drawn box.
protected override void OnContentClick(DataGridViewCellEventArgs e)
{
if (!ReadOnly &&
checkBoxRect.Contains(DataGridView.PointToClient(Cursor.Position)))
base.OnContentClick(e);
}

protected override void OnContentDoubleClick(DataGridViewCellEventArgs e)
{
if (!ReadOnly &&
checkBoxRect.Contains(DataGridView.PointToClient(Cursor.Position)))
base.OnContentDoubleClick(e);
}

// Toggle the checked state by mouse clicks...
protected override void OnMouseUp(DataGridViewCellMouseEventArgs e)
{
base.OnMouseUp(e);

if (!ReadOnly && e.Button == MouseButtons.Left &&
checkBoxRect.Contains(DataGridView.PointToClient(Cursor.Position)))
{
Value = Value == null || !Convert.ToBoolean(Value);
DataGridView.RefreshEdit();
DataGridView.NotifyCurrentCellDirty(true);
}
}

// ... and Space key...
protected override void OnKeyDown(KeyEventArgs e, int rowIndex)
{
base.OnKeyDown(e, rowIndex);
if (!ReadOnly && e.KeyCode == Keys.Space)
{
Value = Value == null || !Convert.ToBoolean(Value.ToString());
DataGridView.RefreshEdit();
DataGridView.NotifyCurrentCellDirty(true);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MDB
{
public class CustomDataGridViewCheckBoxColumn : DataGridViewCheckBoxColumn
{
public CustomDataGridViewCheckBoxColumn() : base() =>
CellTemplate = new CustomDataGridViewCheckBoxCell();

public override DataGridViewCell CellTemplate
{
get => base.CellTemplate;
set
{
if (value != null &&
!value.GetType().IsAssignableFrom(typeof(CustomDataGridViewCheckBoxCell)))
throw new InvalidCastException("CustomDataGridViewCheckBoxCell.");

base.CellTemplate = value;
}
}

[Category("Appearance")]
[DefaultValue(typeof(Size), "32, 32")]
[Description("The size of the check box.")]
public Size CheckBoxSize { get; set; } = new Size(32, 32);

// We should copy the new properties.
public override object Clone()
{
var c = base.Clone() as CustomDataGridViewCheckBoxColumn;
c.CheckBoxSize = CheckBoxSize;
return c;
}
}
}
5 changes: 3 additions & 2 deletions MDB/WindowsFormsApp1/DatabaseFunct (Columns Rows).cs
Original file line number Diff line number Diff line change
Expand Up @@ -1642,9 +1642,9 @@ internal static void LoadRow(KeyValuePair<int, Dictionary<string, dynamic>> entr


}
else if (DGV.Columns[column.Name] is DataGridViewCheckBoxColumn)
else if (DGV.Columns[column.Name] is CustomDataGridViewCheckBoxColumn)
{
DataGridViewCheckBoxCell cell = ColumnTypes.setBoolCellTFVals(new DataGridViewCheckBoxCell());
CustomDataGridViewCheckBoxCell cell = ColumnTypes.setBoolCellTFVals(new CustomDataGridViewCheckBoxCell());

cell.Tag = new Dictionary<string, dynamic>() { { "Enabled", true } };

Expand All @@ -1653,6 +1653,7 @@ internal static void LoadRow(KeyValuePair<int, Dictionary<string, dynamic>> entr
if (value)
{
cellVal = cell.TrueValue;

}


Expand Down
8 changes: 4 additions & 4 deletions MDB/WindowsFormsApp1/DatabaseFunct (Disabler Functions).cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,9 @@ internal static void DisableCellAtColAndRow(CustomDataGridView DGV, string ColKe
DataGridViewComboBoxCell cbcell = (DataGridViewComboBoxCell)cell;
//cbcell.FlatStyle = FlatStyle.Popup;
}
if (cell.GetType() == typeof(DataGridViewCheckBoxCell))
if (cell.GetType() == typeof(CustomDataGridViewCheckBoxCell))
{
DataGridViewCheckBoxCell cbcell = (DataGridViewCheckBoxCell)cell;
CustomDataGridViewCheckBoxCell cbcell = (CustomDataGridViewCheckBoxCell)cell;
cbcell.FlatStyle = FlatStyle.Popup;
}

Expand Down Expand Up @@ -260,9 +260,9 @@ internal static void EnableCellAtColAndRow(CustomDataGridView DGV, string ColKey
DataGridViewComboBoxCell cbcell = (DataGridViewComboBoxCell)cell;
//cbcell.FlatStyle = FlatStyle.Standard;
}
if (cell.GetType() == typeof(DataGridViewCheckBoxCell))
if (cell.GetType() == typeof(CustomDataGridViewCheckBoxCell))
{
DataGridViewCheckBoxCell cbcell = (DataGridViewCheckBoxCell)cell;
CustomDataGridViewCheckBoxCell cbcell = (CustomDataGridViewCheckBoxCell)cell;
cbcell.FlatStyle = FlatStyle.Standard;
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ public void addRowToDataGridViewControl(string colName, bool isPK, bool isATCS,
columnNameCell.Value = colName;

//is Primary Key column
DataGridViewCheckBoxCell isPKCell = columnRow.Cells[dataGridView.Columns.IndexOf(isPrimaryKeyColumn)] as DataGridViewCheckBoxCell;
CustomDataGridViewCheckBoxCell isPKCell = columnRow.Cells[dataGridView.Columns.IndexOf(isPrimaryKeyColumn)] as CustomDataGridViewCheckBoxCell;
ColumnTypes.setBoolCellTFVals(isPKCell);


Expand All @@ -303,11 +303,11 @@ public void addRowToDataGridViewControl(string colName, bool isPK, bool isATCS,
cellVal = isPKCell.TrueValue;
}
isPKCell.Value = cellVal;



//is Auto Table Constructor Script column
DataGridViewCheckBoxCell isATCSCell = columnRow.Cells[dataGridView.Columns.IndexOf(isAutoTableConstructorScriptColumn)] as DataGridViewCheckBoxCell;
CustomDataGridViewCheckBoxCell isATCSCell = columnRow.Cells[dataGridView.Columns.IndexOf(isAutoTableConstructorScriptColumn)] as CustomDataGridViewCheckBoxCell;
ColumnTypes.setBoolCellTFVals(isATCSCell);

//set checkbox state
Expand Down
Loading

0 comments on commit 14b251e

Please sign in to comment.