XPTable.Models.Table.FindNextEditableCell C# (CSharp) Method

FindNextEditableCell() protected method

Returns a CellPos that specifies the next Cell that able to be edited from the specified Cell
protected FindNextEditableCell ( XPTable.Models.CellPos start, bool wrap, bool forward, bool includeStart ) : XPTable.Models.CellPos
start XPTable.Models.CellPos A CellPos that specifies the Cell to start /// searching from
wrap bool Specifies whether to move to the start of the /// next Row when the end of the current Row is reached
forward bool Specifies whether the search should travel /// in a forward direction (top to bottom, left to right) through the Cells
includeStart bool Indicates whether the specified starting /// Cell is included in the search
return XPTable.Models.CellPos
        protected CellPos FindNextEditableCell(CellPos start, bool wrap, bool forward, bool includeStart)
        {
            if (this.ColumnCount == 0 || this.RowCount == 0)
            {
                return CellPos.Empty;
            }

            int startRow = start.Row != -1 ? start.Row : 0;
            int startCol = start.Column != -1 ? start.Column : 0;

            bool first = true;

            if (forward)
            {
                for (int i = startRow; i < this.RowCount; i++)
                {
                    int j = (first ? startCol : 0);

                    for (; j < this.TableModel.Rows[i].Cells.Count; j++)
                    {
                        if (i == startRow && j == startCol)
                        {
                            if (!first)
                            {
                                return CellPos.Empty;
                            }

                            first = false;

                            if (!includeStart)
                            {
                                continue;
                            }
                        }

                        if (this.IsValidCell(i, j) && this.IsValidColumn(j) && this.TableModel[i, j].Editable && this.ColumnModel.Columns[j].Editable)
                        {
                            return new CellPos(i, j);
                        }
                    }

                    if (wrap)
                    {
                        if (i + 1 == this.TableModel.Rows.Count)
                        {
                            i = -1;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }
            else
            {
                for (int i = startRow; i >= 0; i--)
                {
                    int j = (first ? startCol : this.TableModel.Rows[i].Cells.Count);

                    for (; j >= 0; j--)
                    {
                        if (i == startRow && j == startCol)
                        {
                            if (!first)
                            {
                                return CellPos.Empty;
                            }

                            first = false;

                            if (!includeStart)
                            {
                                continue;
                            }
                        }

                        if (this.IsValidCell(i, j) && this.IsValidColumn(j) && this.TableModel[i, j].Editable && this.ColumnModel.Columns[j].Editable)
                        {
                            return new CellPos(i, j);
                        }
                    }

                    if (wrap)
                    {
                        if (i - 1 == -1)
                        {
                            i = this.TableModel.Rows.Count;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }

            return CellPos.Empty;
        }
Table