Example #1
0
        public int IndexOf(string columnName)
        {
            int index = -1;

            for (int i = 0; i < columns.Count; i++)
            {
                SimpleColumn c = this.columns[i] as SimpleColumn;
                if (c.Name == columnName)
                {
                    index = i;
                    break;
                }
            }
            return(index);
        }
Example #2
0
        /// <summary>
        /// Returns an item from the SimpleRow by colum index or name
        /// </summary>
        public object this[object columnIndexOrName]
        {
            get
            {
                int columnIndex;

                if (columnIndexOrName is String)
                {
                    columnIndex = this.table.columns.IndexOf(columnIndexOrName.ToString());

                    if (columnIndex >= 0)
                    {
                        return(items[columnIndex]);
                    }
                    else
                    {
                        throw new IndexOutOfRangeException("Column " + columnIndexOrName.ToString() + " was not found in this SimpleTable.");
                    }
                }
                else if (columnIndexOrName is Int32)
                {
                    columnIndex = (int)columnIndexOrName;

                    if ((columnIndex >= 0) && (columnIndex < items.Count))
                    {
                        return(items[columnIndex]);
                    }
                    else
                    {
                        throw new IndexOutOfRangeException("Index " + columnIndex + " is out of range. This SimpleTable has a column length of " + items.Count + ".");
                    }
                }
                else if (columnIndexOrName is SimpleColumn)
                {
                    SimpleColumn col = columnIndexOrName as SimpleColumn;

                    columnIndex = table.Columns.IndexOf(col.Name);
                    if (columnIndex >= 0)
                    {
                        return(items[columnIndex]);
                    }
                    else
                    {
                        throw new IndexOutOfRangeException("Column [" + col.Name + "] is out of range. This SimpleTable does not contain this column.");
                    }
                }
                else
                {
                    throw new Exception("The indexer must be an Int32, string, or a SimpleColumn");
                }
            }

            set
            {
                int columnIndex;

                if (columnIndexOrName is String)
                {
                    columnIndex = this.table.columns.IndexOf(columnIndexOrName.ToString());

                    if (columnIndex >= 0)
                    {
                        items[columnIndex] = value;
                    }
                    else
                    {
                        throw new IndexOutOfRangeException("Column " + columnIndexOrName.ToString() + " was not found in this SimpleTable.");
                    }
                }
                else if (columnIndexOrName is Int32)
                {
                    columnIndex = (int)columnIndexOrName;

                    if ((columnIndex >= 0) && (columnIndex < items.Count))
                    {
                        items[columnIndex] = value;
                    }
                    else
                    {
                        throw new IndexOutOfRangeException("Index " + columnIndex + " is out of range. This SimpleTable has a column length of " + items.Count + ".");
                    }
                }
                else if (columnIndexOrName is SimpleColumn)
                {
                    SimpleColumn col = columnIndexOrName as SimpleColumn;

                    columnIndex = table.Columns.IndexOf(col.Name);
                    if (columnIndex >= 0)
                    {
                        items[columnIndex] = value;
                    }
                    else
                    {
                        throw new IndexOutOfRangeException("Column [" + col.Name + "] is out of range. This SimpleTable does not contain this column.");
                    }
                }
                else
                {
                    throw new Exception("The indexer must be an Int32, a SimpleColumn, or a string");
                }
            }
        }