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