Skip to content

Commit

Permalink
fixed column height for high dpi, added checklist custom font, update…
Browse files Browse the repository at this point in the history
…d version
  • Loading branch information
davidegironi committed Feb 16, 2024
1 parent 78c1d32 commit 54ae03b
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 22 deletions.
32 changes: 16 additions & 16 deletions AdvancedDataGridView/AdvancedDataGridView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -786,21 +786,21 @@ public void TriggerSortStringChanged()
}
//sort datasource
if (sortEventArgs.Cancel == false)
{
if (this.DataSource is BindingSource bindingsource)
{
bindingsource.Sort = sortEventArgs.SortString;
}
else if (this.DataSource is DataView dataview)
{
dataview.Sort = sortEventArgs.SortString;
}
else if (this.DataSource is DataTable datatable)
{
if (datatable.DefaultView != null)
datatable.DefaultView.Sort = sortEventArgs.SortString;
}
}
{
if (this.DataSource is BindingSource bindingsource)
{
bindingsource.Sort = sortEventArgs.SortString;
}
else if (this.DataSource is DataView dataview)
{
dataview.Sort = sortEventArgs.SortString;
}
else if (this.DataSource is DataTable datatable)
{
if (datatable.DefaultView != null)
datatable.DefaultView.Sort = sortEventArgs.SortString;
}
}
//invoke SortStringChanged
if (!_sortStringChangedInvokeBeforeDatasourceUpdate)
{
Expand Down Expand Up @@ -1423,7 +1423,7 @@ private void Cell_FilterPopup(object sender, ColumnHeaderCellEventArgs e)
if (_filterOrderList.Count() > 0 && _filterOrderList.Last() == column.Name)
filterMenu.Show(this, rect.Left, rect.Bottom, true);
else
filterMenu.Show(this, rect.Left, rect.Bottom, MenuStrip.GetValuesForFilter(this, column.Name));
filterMenu.Show(this, rect.Left, rect.Bottom, column.Name);
}
}
}
Expand Down
Binary file modified AdvancedDataGridView/AdvancedDataGridView.csproj
Binary file not shown.
4 changes: 3 additions & 1 deletion AdvancedDataGridView/ColumnHeaderCell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public ColumnHeaderCell(DataGridViewColumnHeaderCell oldCell, bool filterEnabled
Style = oldCell.Style;
_filterEnabled = filterEnabled;

_filterButtonImageSize = new Size((int)Math.Round(oldCell.Size.Height * 0.8), (int)Math.Round(oldCell.Size.Height * 0.8));

ColumnHeaderCell oldCellt = oldCell as ColumnHeaderCell;
if (oldCellt != null && oldCellt.MenuStrip != null)
{
Expand Down Expand Up @@ -653,7 +655,7 @@ private Rectangle GetFilterBounds(bool withOffset = true)

Point p = new Point(
(withOffset ? cell.Right : cell.Width) - _filterButtonImageSize.Width - _filterButtonMargin.Right,
(withOffset ? cell.Bottom : cell.Height) - _filterButtonImageSize.Height - _filterButtonMargin.Bottom);
(withOffset ? cell.Bottom + 2 : cell.Height) - _filterButtonImageSize.Height - _filterButtonMargin.Bottom);

return new Rectangle(p, _filterButtonImageSize);
}
Expand Down
23 changes: 19 additions & 4 deletions AdvancedDataGridView/MenuStrip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -511,21 +511,27 @@ public void SetLoadedMode(bool enabled)
/// <param name="control"></param>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="vals"></param>
public void Show(Control control, int x, int y, IEnumerable<DataGridViewCell> vals)
/// <param name="columnName"></param>
public void Show(Control control, int x, int y, string columnName)
{
_removedNodes = new TreeNodeItemSelector[] { };
_removedsessionNodes = new TreeNodeItemSelector[] { };

//add nodes
BuildNodes(vals);
DataGridView dataGridView = control as DataGridView;
IEnumerable<DataGridViewCell> vals = dataGridView != null ? GetValuesForFilter(dataGridView, columnName) : Enumerable.Empty<DataGridViewCell>();
BuildNodes(vals, dataGridView, columnName);
//set the starting nodes
_startingNodes = DuplicateNodes(_loadedNodes);

if (_activeFilterType == FilterType.Custom)
SetNodesCheckState(_loadedNodes, false);
base.Show(control, x, y);

//force checklist refresh
checkList.BeginUpdate();
checkList.EndUpdate();

_filterclick = false;

_checkTextFilterChangedEnabled = false;
Expand Down Expand Up @@ -927,7 +933,9 @@ private static string FormatFilterString(string text)
/// Add nodes to checkList
/// </summary>
/// <param name="vals"></param>
private void BuildNodes(IEnumerable<DataGridViewCell> vals)
/// <param name="dataGridView"></param>
/// <param name="columnName"></param>
private void BuildNodes(IEnumerable<DataGridViewCell> vals, DataGridView dataGridView, string columnName)
{
if (!IsFilterChecklistEnabled)
return;
Expand Down Expand Up @@ -1105,9 +1113,16 @@ orderby cs.Key ascending
//add string nodes
else
{
//get custom font by columnName
Font nodeFont = null;
if (dataGridView != null && !String.IsNullOrEmpty(columnName))
nodeFont = dataGridView.Columns[columnName].DefaultCellStyle.Font;

foreach (var v in nonulls.GroupBy(c => c.Value).OrderBy(g => g.Key))
{
TreeNodeItemSelector node = TreeNodeItemSelector.CreateNode(v.First().FormattedValue.ToString(), v.Key, CheckState.Checked, TreeNodeItemSelector.CustomNodeType.Default);
if (nodeFont != null)
node.NodeFont = nodeFont;
ChecklistAddNode(node);
}
}
Expand Down
Binary file modified AdvancedDataGridViewSample/AdvancedDataGridViewSample.csproj
Binary file not shown.
2 changes: 1 addition & 1 deletion _DevTools/AutoBuilder.config.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ $solutionName = "AdvancedDataGridView"
$versionMajor = "1"
$versionMinor = "2"
$versionBuild = GetVersionBuild
$versionRevision = "11"
$versionRevision = "12"
#build version number
$version = GetVersion $versionMajor $versionMinor $versionBuild $versionRevision

Expand Down

0 comments on commit 54ae03b

Please sign in to comment.