Skip to content

Commit

Permalink
Adjusted column width tolerance
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirdock committed Sep 9, 2019
1 parent 2c697af commit d0268e1
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions DataTableConverter/View/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public partial class Form1 : Form
private string FilePath = string.Empty;
private OrderType OrderType = OrderType.Windows;
private Dictionary<string, int> ColumnWidths;
private readonly int ColumnWidthTolerance = 10;

internal Form1(DataTable table = null)
{
Expand Down Expand Up @@ -236,7 +237,7 @@ private void SetWidth(bool adjustColumnWidth)
private void SetOptimalColumnWidth(DataGridViewColumn col)
{
string result = sourceTable.AsEnumerable().Select(row => row[col.Name].ToString()).Concat(new string[] { col.Name }).Aggregate(string.Empty, (seed, f) => f.Length > seed.Length ? f : seed);
col.Width = TextRenderer.MeasureText(result, dgTable.DefaultCellStyle.Font).Width + 5;
col.Width = TextRenderer.MeasureText(result, dgTable.DefaultCellStyle.Font).Width + ColumnWidthTolerance;

AddColumnWidth(col);
}
Expand Down Expand Up @@ -990,7 +991,7 @@ private void wiederholenToolStripMenuItem_Click(object sender, EventArgs e)

private void dgTable_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
int width = TextRenderer.MeasureText(dgTable[e.ColumnIndex, e.RowIndex].Value.ToString(), dgTable.DefaultCellStyle.Font).Width + 5;
int width = TextRenderer.MeasureText(dgTable[e.ColumnIndex, e.RowIndex].Value.ToString(), dgTable.DefaultCellStyle.Font).Width + ColumnWidthTolerance;
DataGridViewColumn col = dgTable.Columns[e.ColumnIndex];
if (width > col.Width)
{
Expand Down

0 comments on commit d0268e1

Please sign in to comment.