B2019-162 Allow Table column widths to be specified. Shut-off automatic resize function when converting

This commit is contained in:
Rich 2019-10-29 17:30:12 +00:00
parent ba20b719c6
commit 4a75b61f46

View File

@ -1823,8 +1823,8 @@ namespace Volian.Controls.Library
this.Size = new Size(wid + difW, height + difH);
}
}
public void ConvertTextCellToRTF(int r, int c)
// B2019-162 Allow grids to not automatically adjust the cell widths
public void ConvertTextCellToRTF(int r, int c, bool adjustWidth)
{
using (StepRTB trtb = new StepRTB())
{
@ -1867,6 +1867,9 @@ namespace Volian.Controls.Library
}
// find the needed cell width
trtb.AdjustWidthForContent();
// B2019-162 Allow grids to not automatically adjust the cell widths
if(adjustWidth)trtb.AdjustWidthForContent();
if (dummyCharWidth)
{
trtb.Text = ""; // clear out the dummy character before saving
@ -1879,9 +1882,8 @@ namespace Volian.Controls.Library
//sel.UserData = trtb.ContentsRectangle.Height;
// Now adjust the Height and Width in the defined merge ranges
AdjustMergeRangeHeightWidth(r, c, trtb, tstr, AllowWidthShrink);
// B2019-162 Allow grids to not automatically adjust the cell widths
AdjustMergeRangeHeightWidth(r, c, trtb, tstr, AllowWidthShrink,adjustWidth);
//// Now see the the selected row,col is in the defined merge ranges
//bool mrgrows = false;
//bool mrgcols = false;
@ -1952,44 +1954,42 @@ namespace Volian.Controls.Library
//}
}
}
private void AdjustCellHeightWidth(int r, int c)
{
using (StepRTB trtb = new StepRTB())
{
string tstr = null;
bool dummyCharWidth = false;
bool AllowWidthShrink = false;
trtb.SetTableGridCellRTFPrefix(this.Font);
trtb.Clear();
trtb.Font = this.Font;
trtb.Rtf = (string)this[r, c];
tstr = trtb.Text;
if (tstr != null && tstr.Length > 0)
AllowWidthShrink = tstr.Contains("#Link:");
else
{
trtb.Text = "X"; // this is to trick steprtf in giving a char width to fit one character
// note that a space character was too small.
dummyCharWidth = true;
}
// find the needed cell width
trtb.AdjustWidthForContent();
//private void AdjustCellHeightWidth(int r, int c)
//{
// using (StepRTB trtb = new StepRTB())
// {
// string tstr = null;
// bool dummyCharWidth = false;
// bool AllowWidthShrink = false;
// trtb.SetTableGridCellRTFPrefix(this.Font);
// trtb.Clear();
// trtb.Font = this.Font;
// trtb.Rtf = (string)this[r, c];
// tstr = trtb.Text;
// if (tstr != null && tstr.Length > 0)
// AllowWidthShrink = tstr.Contains("#Link:");
// else
// {
// trtb.Text = "X"; // this is to trick steprtf in giving a char width to fit one character
// // note that a space character was too small.
// dummyCharWidth = true;
// }
// // find the needed cell width
// trtb.AdjustWidthForContent();
// if (dummyCharWidth)
// {
// trtb.Text = ""; // clear out the dummy character before saving
// dummyCharWidth = false;
// }
if (dummyCharWidth)
{
trtb.Text = ""; // clear out the dummy character before saving
dummyCharWidth = false;
}
this.Select(r, c, false);
CellRange sel = this.Selection;
// // Now adjust the Height and Width in the defined merge ranges
// AdjustMergeRangeHeightWidth(r, c, trtb, tstr, AllowWidthShrink,true);
// }
//}
// Now adjust the Height and Width in the defined merge ranges
AdjustMergeRangeHeightWidth(r, c, trtb, tstr, AllowWidthShrink);
}
}
private void AdjustMergeRangeHeightWidth(int r, int c, StepRTB trtb, string tstr, bool AllowWidthShrink)
// B2019-162 Allow grids to not automatically adjust the cell widths
private void AdjustMergeRangeHeightWidth(int r, int c, StepRTB trtb, string tstr, bool AllowWidthShrink, bool adjustWidth)
{
bool mrgrows = false;
bool mrgcols = false;
@ -2025,11 +2025,15 @@ namespace Volian.Controls.Library
if (!mrgcols)
{
// add adjustment for grid and cell borders
int newwidth = trtb.Width + 3; // 2;
if (newwidth > (this.Cols[c].Width == -1 ? this.Cols.DefaultSize : this.Cols[c].Width) || AllowWidthShrink || r == 0)
this.Cols[c].Width = newwidth;
// B2019-162 Allow grids to not automatically adjust the cell widths
if (adjustWidth)
{
int newwidth = trtb.Width + 3; // 2;
if (newwidth > (this.Cols[c].Width == -1 ? this.Cols.DefaultSize : this.Cols[c].Width) || AllowWidthShrink || r == 0)
this.Cols[c].Width = newwidth;
}
}
}
}
if (mrgrows && tstr != null)
{
CellRange cr = GetMergedRange(r, c);
@ -2232,7 +2236,13 @@ namespace Volian.Controls.Library
#endregion // Grid Size Adjustments
#region Cell Text
// B2019-162 Allow grids to not automatically adjust the cell widths
public void MakeRTFcells()
{
MakeRTFcells(true);
}
// B2019-162 Allow grids to not automatically adjust the cell widths
public void MakeRTFcells(bool adjustwidth)
{
// This will spin through all the cells in the grid:
// - convert the text to RTF if needed
@ -2241,10 +2251,13 @@ namespace Volian.Controls.Library
{
this.Rows[r].Height = Rows.DefaultSize;//_minRowHeight;//20;//10;
for (int c = 0; c < this.Cols.Count; c++)
this.ConvertTextCellToRTF(r, c);
{
// B2019-162 Allow grids to not automatically adjust the cell widths
this.ConvertTextCellToRTF(r, c, adjustwidth);
}
}
TrimColumnWidths();
// B2019-162 Allow grids to not automatically adjust the cell widths
if(adjustwidth) TrimColumnWidths();
RemoveBlankSpaceFromRows();
SetupCellUserData();
this.AdjustGridControlSize();