This commit is contained in:
John Jenko 2011-04-20 13:59:14 +00:00
parent 05c97e9aed
commit 6a63b4634c
2 changed files with 160 additions and 59 deletions

View File

@ -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)

View File

@ -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()
@ -1899,58 +1898,141 @@ namespace Volian.Controls.Library
C1.Win.C1FlexGrid.CellRange sel = GetMergedRange(this.Selection.r1, this.Selection.c1);
return MergedRanges.Contains(sel);
}
public void SplitSelection(bool bSplitCols)
{
//Console.WriteLine("SplitSelection this.selection {0}", this.Selection);
//Debug_WritelineMySelection();
C1.Win.C1FlexGrid.CellRange sel = this.GetMergedRange(this.Selection.r1, this.Selection.c1);
//foreach (CellRange sel in MySelection)
//{
if (this.MergedRanges.Contains(sel))
this.MergedRanges.Remove(sel);
else //split cells
{
if (bSplitCols)
SplitSelectionColumns();
else
SplitSelectionRows();
}
//}
this.Refresh();
this.AdjustGridControlSize();
}
public void SplitSelection(bool bSplitCols)
{
//Console.WriteLine("SplitSelection this.selection {0}", this.Selection);
//Debug_WritelineMySelection();
//C1.Win.C1FlexGrid.CellRange sel = this.GetMergedRange(this.Selection.r1, this.Selection.c1);
//Console.WriteLine("SplitSelection myselection {0}", MySelection);
//foreach (CellRange sel in MySelection)
//{
// //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();
//RefreshMergeRangeCollection();
this.AdjustGridControlSize();
}
private void SplitSelectionColumns()
{
//Console.WriteLine("SplitSelectionColumns this.selection {0}", this.Selection);
//Debug_WritelineMySelection();
CellRange cr = this.Selection;
int numSelCols = (cr.c2 - cr.c1) + 1;
// for each column in the selection, add a new column
for (int c = cr.c2; c >= cr.c1; c--)
InsertColumnAfter();
// include new columns in selection
this.Select(cr.r1, cr.c1, cr.r2, cr.c2 + numSelCols);
cr = this.Selection;
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 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);
//Console.WriteLine("Cell[{0},{1}].Width = {2}", cr.r1, c, recWidth);
}
}
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 + ((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))
{
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);
}
}
// Adjust selected column widths
for (int c = cr.c1; c <= cr.c2; c++)
{
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);
}
}
}
private void SplitSelectionRows()
{
@ -1962,10 +2044,18 @@ 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++)
@ -1973,10 +2063,13 @@ namespace Volian.Controls.Library
{
if (!this.IsCellSelected(r, c))
{
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);
CellRange crTmp = GetMergedRange(r, c);
if (crTmp.IsSingleCell)
{
CellRange tcr = this.GetCellRange(r, c, r + 1, c);
this.MergedRanges.Add(tcr);
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