B2015-042: Fixed crashes when deleting rows/columns when table has merged cells. Other general improvements of table row/column deletion.
This commit is contained in:
parent
5cbbd3e581
commit
3deeeb429e
@ -2858,9 +2858,9 @@ namespace Volian.Controls.Library
|
||||
if (row >= 0)
|
||||
{
|
||||
CellRange cr = this.Selection;
|
||||
rtn = true;
|
||||
//rtn = true; // KBR: is this wrong, i.e. should it be like ColIsInMergeRange
|
||||
int c = cr.c1;
|
||||
while (rtn && (c <= cr.c2))
|
||||
while (!rtn && (c <= cr.c2))
|
||||
{
|
||||
int idx = this.MergedRanges.IndexOf(row, c);
|
||||
rtn = (idx > -1);
|
||||
@ -2880,7 +2880,7 @@ namespace Volian.Controls.Library
|
||||
int r = cr.r1;
|
||||
while (!rtn && (r <= cr.r2))
|
||||
{
|
||||
int idx = this.MergedRanges.IndexOf(col, r);
|
||||
int idx = this.MergedRanges.IndexOf(r, col);
|
||||
rtn = (idx > -1);
|
||||
r++;
|
||||
}
|
||||
@ -3018,7 +3018,7 @@ namespace Volian.Controls.Library
|
||||
}
|
||||
DialogResult dr = MessageBox.Show(msg, title, MessageBoxButtons.YesNo);
|
||||
if (dr == DialogResult.Yes)
|
||||
RemoveSelectedCells();//RemoveColumns(this.Selection.r1, this.Selection.c1, 1);
|
||||
RemoveColumns(this.Selection.r1, this.Selection.c1, 1+this.Selection.c2-this.Selection.c1);
|
||||
else
|
||||
Select(saveCR);
|
||||
}
|
||||
@ -3029,7 +3029,6 @@ namespace Volian.Controls.Library
|
||||
string title = "";
|
||||
CellRange saveCR = Selection;
|
||||
this.SelectionMode = SelectionModeEnum.RowRange;
|
||||
//this.Select(this.Selection.r1, this.Selection.c1,);
|
||||
this.Select(Selection.r1, 0, Selection.r2, Cols.Count - 1);
|
||||
this.SelectionMode = SelectionModeEnum.Default;
|
||||
if (Selection.r1 != Selection.r2)
|
||||
@ -3044,7 +3043,7 @@ namespace Volian.Controls.Library
|
||||
}
|
||||
DialogResult dr = MessageBox.Show(msg, title, MessageBoxButtons.YesNo);
|
||||
if (dr == DialogResult.Yes)
|
||||
this.RemoveSelectedCells();//this.RemoveRows(this.Selection.r1, this.Selection.c1, 1);
|
||||
this.RemoveRows(this.Selection.r1, this.Selection.c1, 1 + this.Selection.r2 - this.Selection.r1);
|
||||
else
|
||||
Select(saveCR);
|
||||
}
|
||||
@ -3054,8 +3053,6 @@ namespace Volian.Controls.Library
|
||||
bool mergedRow = false;
|
||||
for (int i = 0; i < cnt; i++)
|
||||
{
|
||||
//if (this.RowIsInMergeRange(strow))
|
||||
//{
|
||||
for (int cl = 0; cl < this.Cols.Count && !mergedRow; cl++)
|
||||
{
|
||||
int idx = this.MergedRanges.IndexOf(strow, cl);
|
||||
@ -3064,18 +3061,12 @@ namespace Volian.Controls.Library
|
||||
CellRange cr = this.MergedRanges[idx];
|
||||
if (cr.r1 < cr.r2)
|
||||
mergedRow = true;
|
||||
//this[cr.r1 + 1, cr.c1] = this[cr.r1, cr.c1];
|
||||
}
|
||||
cl++;
|
||||
}
|
||||
//}
|
||||
this.Rows.Remove(strow);
|
||||
this.AdjustMergedRows(strow, false, true);
|
||||
//if (mergedRow)
|
||||
//{
|
||||
//cnt++;
|
||||
mergedRow = false;
|
||||
//}
|
||||
}
|
||||
MyBorders.DeleteRows(strow, cnt);
|
||||
this.AdjustGridControlSize();
|
||||
@ -3086,8 +3077,6 @@ namespace Volian.Controls.Library
|
||||
bool mergedCol = false;
|
||||
for (int i = 0; i < cnt; i++)
|
||||
{
|
||||
//if (this.ColIsInMergeRange(stcol))
|
||||
//{
|
||||
for (int rw = 0; rw < this.Rows.Count && !mergedCol; rw++)
|
||||
{
|
||||
int idx = this.MergedRanges.IndexOf(rw, stcol);
|
||||
@ -3096,66 +3085,15 @@ namespace Volian.Controls.Library
|
||||
CellRange cr = this.MergedRanges[idx];
|
||||
if (cr.c1 < cr.c2)
|
||||
mergedCol = true;
|
||||
//this[cr.r1, cr.c1 + 1] = this[cr.r1, cr.c1];
|
||||
}
|
||||
}
|
||||
//}
|
||||
this.Cols.Remove(stcol);
|
||||
this.AdjustMergedColumns(stcol, false, true);
|
||||
//if (mergedCol)
|
||||
//{
|
||||
// //cnt++;
|
||||
mergedCol = false;
|
||||
//}
|
||||
}
|
||||
MyBorders.DeleteColumns(stcol, cnt);
|
||||
this.AdjustGridControlSize();
|
||||
}
|
||||
|
||||
public void RemoveSelectedCells()
|
||||
{
|
||||
bool didremove = false;
|
||||
int lastRow = this.Rows.Count - 1;
|
||||
int lastCol = this.Cols.Count - 1;
|
||||
CellRange cr = this.Selection;
|
||||
|
||||
// r2 is last row (or in merge range containing last row)
|
||||
// r1 is first row or r1-m (m is in merge range) is first row
|
||||
// we can remove columns c1 through c2
|
||||
int idx = this.MergedRanges.IndexOf(cr);
|
||||
//int idx = this.MergedRanges.IndexOf(cr.r2, cr.c2);
|
||||
CellRange mr = new CellRange();
|
||||
if (idx > -1) mr = this.MergedRanges[idx];
|
||||
if (cr.r2 == lastRow || idx > -1 && mr.r2 == lastRow)//RowIsInMergeRange(grd,cr.r2))
|
||||
{
|
||||
if (cr.r1 == 0 || this.RowIsInMergeRange(cr.r1 - 1))
|
||||
{
|
||||
this.RemoveColumns(cr.r1, cr.c1, cr.RightCol - cr.LeftCol + 1);// remove selected columns
|
||||
didremove = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// c2 is last column (or in merge range containing last column)
|
||||
// c1 is first column or c1-m (m is merge range) is first column
|
||||
// we can remove rows r1 through r2
|
||||
|
||||
if (cr.c2 == lastCol || idx > -1 && mr.c2 == lastCol)//ColIsInMergeRange(grd,cr.c1-1))
|
||||
{
|
||||
if (cr.c1 == 0 || this.ColIsInMergeRange(cr.c1 - 1))
|
||||
{
|
||||
// remove selected rows
|
||||
this.RemoveRows(cr.r1, cr.c1, cr.BottomRow - cr.TopRow + 1);
|
||||
didremove = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!didremove)
|
||||
MessageBox.Show("Cannot Removed Part of a Row or Column.\n\nNote: This function allows you to delete one or more rows/columns at time.", "Invalid Selection",MessageBoxButtons.OK,MessageBoxIcon.Hand);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
#endregion //Grid Add and Remove Row / Column
|
||||
|
||||
#region Copy/Paste
|
||||
|
Loading…
x
Reference in New Issue
Block a user