diff --git a/DataTableConverter/View/Form1.cs b/DataTableConverter/View/Form1.cs index 28ecd4f..5693fcd 100644 --- a/DataTableConverter/View/Form1.cs +++ b/DataTableConverter/View/Form1.cs @@ -39,6 +39,7 @@ public partial class Form1 : Form private string FilePath = string.Empty; private OrderType OrderType = OrderType.Windows; private Dictionary ColumnWidths; + private readonly int ColumnWidthTolerance = 10; internal Form1(DataTable table = null) { @@ -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); } @@ -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) {