This commit is contained in:
parent
05c97e9aed
commit
6a63b4634c
@ -1819,13 +1819,21 @@ namespace Volian.Controls.Library
|
||||
#region Table Grid Merge/Split
|
||||
private void btnTblDgnSplitCells_ToRows_Click(object sender, EventArgs e)
|
||||
{
|
||||
// without the BeginUpdate/EndUpdate, you will see the table jump around while
|
||||
// it is being adjusted
|
||||
MyFlexGrid.BeginUpdate();
|
||||
MyFlexGrid.SplitSelection(false);
|
||||
MyFlexGrid.EndUpdate();
|
||||
}
|
||||
#endregion
|
||||
|
||||
private void btnTblDgnSplitCellsToCols_Click(object sender, EventArgs e)
|
||||
{
|
||||
// without the BeginUpdate/EndUpdate, you will see the table jump around while
|
||||
// it is being adjusted
|
||||
MyFlexGrid.BeginUpdate();
|
||||
MyFlexGrid.SplitSelection(true);
|
||||
MyFlexGrid.EndUpdate();
|
||||
}
|
||||
|
||||
private void btnTblDgnMergeCells_Click(object sender, EventArgs e)
|
||||
|
@ -1250,7 +1250,6 @@ namespace Volian.Controls.Library
|
||||
|
||||
this.Size = new Size(wid + difW, height + difH);
|
||||
}
|
||||
//this.Refresh();
|
||||
}
|
||||
|
||||
public void ConvertTextCellToRTF(int r, int c)
|
||||
@ -1891,7 +1890,7 @@ namespace Volian.Controls.Library
|
||||
|
||||
public void MergeSelection()
|
||||
{
|
||||
this.MergedRanges.Add(this.Selection);
|
||||
this.MergedRanges.Add(this.Selection,true);
|
||||
this.Invalidate();
|
||||
}
|
||||
public bool IsInMergeRange()
|
||||
@ -1903,52 +1902,135 @@ namespace Volian.Controls.Library
|
||||
{
|
||||
//Console.WriteLine("SplitSelection this.selection {0}", this.Selection);
|
||||
//Debug_WritelineMySelection();
|
||||
C1.Win.C1FlexGrid.CellRange sel = this.GetMergedRange(this.Selection.r1, this.Selection.c1);
|
||||
//C1.Win.C1FlexGrid.CellRange sel = this.GetMergedRange(this.Selection.r1, this.Selection.c1);
|
||||
//Console.WriteLine("SplitSelection myselection {0}", MySelection);
|
||||
//foreach (CellRange sel in MySelection)
|
||||
//{
|
||||
if (this.MergedRanges.Contains(sel))
|
||||
this.MergedRanges.Remove(sel);
|
||||
else //split cells
|
||||
{
|
||||
// //Console.WriteLine("SplitSelection foreach sel {0}", sel);
|
||||
// if (sel.IsSingleCell)
|
||||
// this.MergedRanges.Remove(sel);
|
||||
// if (!(this.MergedRanges.Contains(sel)) && !didit)
|
||||
// if (bSplitCols)
|
||||
// SplitSelectionColumns();
|
||||
// else
|
||||
// SplitSelectionRows();
|
||||
// didit = true;
|
||||
//}
|
||||
if (bSplitCols)
|
||||
SplitSelectionColumns();
|
||||
else
|
||||
SplitSelectionRows();
|
||||
}
|
||||
//Debug_WritelineMySelection();
|
||||
//foreach (CellRange sel in MySelection)
|
||||
//{
|
||||
// //Console.WriteLine("SplitSelection foreach sel {0}", sel);
|
||||
// if (this.MergedRanges.Contains(sel))
|
||||
// SplitMergedRange(sel, bSplitCols);
|
||||
//}
|
||||
this.Refresh();
|
||||
//this.Refresh();
|
||||
//RefreshMergeRangeCollection();
|
||||
this.AdjustGridControlSize();
|
||||
}
|
||||
|
||||
private void SplitMergedRange(CellRange sel, bool bSplitCols)
|
||||
{
|
||||
int sR = sel.r1;
|
||||
int eR = sel.r2;
|
||||
int sC = sel.c1;
|
||||
int eC = sel.c2;
|
||||
if (bSplitCols && (IsMergedCols(sel) && !IsMergedRows(sel)) ||
|
||||
(!bSplitCols && (IsMergedRows(sel) && !IsMergedCols(sel))))
|
||||
MergedRanges.Remove(sel);
|
||||
else
|
||||
{
|
||||
CellRange saveSelection = Selection;
|
||||
if (bSplitCols && IsMergedRows(sel))
|
||||
{
|
||||
MergedRanges.Remove(sel);
|
||||
for (int c = sC; c <= eC; c++)
|
||||
{
|
||||
Select(sR, c, eR, c);
|
||||
MergeSelection();
|
||||
}
|
||||
}
|
||||
else if (!bSplitCols && IsMergedCols(sel))
|
||||
{
|
||||
MergedRanges.Remove(sel);
|
||||
for (int r = sR; r <= eR; r++)
|
||||
{
|
||||
Select(r, sC, r, eC);
|
||||
MergeSelection();
|
||||
}
|
||||
}
|
||||
Select(saveSelection);
|
||||
}
|
||||
}
|
||||
private bool IsMergedRows(CellRange sel)
|
||||
{
|
||||
return (sel.r1 != sel.r2);
|
||||
}
|
||||
private bool IsMergedCols(CellRange sel)
|
||||
{
|
||||
return (sel.c1 != sel.c2);
|
||||
}
|
||||
private void SplitSelectionColumns()
|
||||
{
|
||||
bool nonMergedInSelection = false;
|
||||
//Console.WriteLine("SplitSelectionColumns this.selection {0}", this.Selection);
|
||||
//Debug_WritelineMySelection();
|
||||
CellRange cr = this.Selection;
|
||||
int numSelCols = (cr.c2 - cr.c1) + 1;
|
||||
foreach (CellRange sel in MySelection)
|
||||
{
|
||||
if (!this.MergedRanges.Contains(sel))
|
||||
nonMergedInSelection = true;
|
||||
}
|
||||
// for each column in the selection, add a new column
|
||||
if (nonMergedInSelection)
|
||||
{
|
||||
for (int c = cr.c2; c >= cr.c1; c--)
|
||||
{
|
||||
Select(cr.r1, c, cr.r2, c);
|
||||
InsertColumnAfter();
|
||||
}
|
||||
}
|
||||
// include new columns in selection
|
||||
this.Select(cr.r1, cr.c1, cr.r2, cr.c2 + numSelCols);
|
||||
this.Select(cr.r1, cr.c1, cr.r2, cr.c2 + ((nonMergedInSelection) ? numSelCols : 0));
|
||||
//if a merged range is part of the selectin, try to split it
|
||||
foreach (CellRange sel in MySelection)
|
||||
{
|
||||
//Console.WriteLine("SplitSelection foreach sel {0}", sel);
|
||||
if (this.MergedRanges.Contains(sel))
|
||||
SplitMergedRange(sel, true);
|
||||
}
|
||||
cr = this.Selection;
|
||||
if (nonMergedInSelection)
|
||||
{
|
||||
for (int r = 0; r < this.Rows.Count; r++)
|
||||
for (int c = cr.c1; c <= cr.c2; c += 2)
|
||||
{
|
||||
if (!this.IsCellSelected(r, c))
|
||||
{
|
||||
//this.Select(r, c, r, c + 1);
|
||||
CellRange crTmp = GetMergedRange(r, c);
|
||||
if (crTmp.IsSingleCell)
|
||||
{
|
||||
CellRange tcr = this.GetCellRange(r, c, r, c + 1);
|
||||
this.MergedRanges.Add(tcr);
|
||||
this.Invalidate();
|
||||
}
|
||||
//CellRange tcr = this.GetCellRange(r, c, r, c + 1);
|
||||
//this.MergedRanges.Add(tcr);
|
||||
}
|
||||
}
|
||||
//this.Select(cr);
|
||||
// Adjust selected column widths
|
||||
for (int c = cr.c1; c <= cr.c2; c++)
|
||||
{
|
||||
int recWidth = this.GetCellRect(cr.r1, c).Width;
|
||||
this.Cols[c].Width = Math.Max(recWidth / 2, _minColSplitWidth);
|
||||
int recWidth = (Cols[c].Width < 0) ? Cols.DefaultSize : Cols[c].Width; // this.GetCellRect(cr.r1, c).Width;
|
||||
int newWidth = Math.Max(recWidth / 2, _minColSplitWidth);
|
||||
this.Cols[c].Width = newWidth;
|
||||
//Console.WriteLine("Cell[{0},{1}].Width = {2}", cr.r1, c, recWidth);
|
||||
//Console.WriteLine("Cell[{0},{1}].NewWidth = {2}", cr.r1, c, newWidth);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1962,21 +2044,32 @@ namespace Volian.Controls.Library
|
||||
for (int r = cr.r2; r >= cr.r1; r--)
|
||||
{
|
||||
//Console.WriteLine("Inserted new Row at [{0},{1}]", r, cr.c1);
|
||||
Select(r, cr.c1, r, cr.c2);
|
||||
InsertRowAfter();
|
||||
}
|
||||
// include new rows in selection
|
||||
this.Select(cr.r1, cr.c1, cr.r2 + numSelRows, cr.c2);
|
||||
//if a merged range is part of the selectin, try to split it
|
||||
foreach (CellRange sel in MySelection)
|
||||
{
|
||||
//Console.WriteLine("SplitSelection foreach sel {0}", sel);
|
||||
if (this.MergedRanges.Contains(sel))
|
||||
SplitMergedRange(sel, false);
|
||||
}
|
||||
cr = this.Selection;
|
||||
//Console.WriteLine(" After Insert [{0},{1}] - [{2},{3}]", cr.r1, cr.c1, cr.r2, cr.c2);
|
||||
for (int c = 0; c < this.Cols.Count; c++)
|
||||
for (int r = cr.r1; r <= cr.r2; r += 2)
|
||||
{
|
||||
if (!this.IsCellSelected(r, c))
|
||||
{
|
||||
CellRange crTmp = GetMergedRange(r, c);
|
||||
if (crTmp.IsSingleCell)
|
||||
{
|
||||
CellRange tcr = this.GetCellRange(r, c, r + 1, c);
|
||||
this.MergedRanges.Add(tcr);
|
||||
//Console.WriteLine("cellrange {0}", tcr);
|
||||
//Console.WriteLine("merge [{0},{1}] - [{2},{3}]", r, c, r + 1, c);
|
||||
this.Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
// Adjust selected Row Heights
|
||||
@ -2106,9 +2199,9 @@ namespace Volian.Controls.Library
|
||||
if (left)
|
||||
{
|
||||
if (inspos == cr.c1)
|
||||
tstr = this[cr.r1, cr.c1 + 1].ToString();
|
||||
tstr = (this[cr.r1, cr.c1 + 1] == null)?"":this[cr.r1, cr.c1 + 1].ToString();
|
||||
else
|
||||
tstr = this[cr.r1, cr.c1].ToString();
|
||||
tstr = (this[cr.r1, cr.c1] == null) ? "" : this[cr.r1, cr.c1].ToString();
|
||||
newcol = cr.c1;
|
||||
}
|
||||
else
|
||||
|
Loading…
x
Reference in New Issue
Block a user