Пример #1
0
        public void Remove()
        {
            DataTable            table = new DataTable("test_table");
            DataColumnCollection cols  = table.Columns;

            cols.Add("test");
            cols.Add("test2");
            cols.Add("test3");
            cols.Add("test4");

            Assert.Equal(4, cols.Count);
            cols.Remove("test2");
            Assert.Equal(3, cols.Count);
            cols.Remove("TEST3");
            Assert.Equal(2, cols.Count);

            // Column '_test_' does not belong to table test_table.
            Assert.Throws <ArgumentException>(() => cols.Remove("_test_"));

            cols.Add();
            cols.Add();
            cols.Add();
            cols.Add();

            Assert.Equal(6, cols.Count);
            cols.Remove(cols[0]);
            cols.Remove(cols[0]);
            Assert.Equal(4, cols.Count);
            Assert.Equal("Column1", cols[0].ColumnName);

            // Cannot remove a column that doesn't belong to this table.
            Assert.Throws <ArgumentException>(() => cols.Remove(new DataColumn("Column10")));

            cols.Add();
            cols.Add();
            cols.Add();
            cols.Add();

            Assert.Equal(8, cols.Count);
            cols.RemoveAt(7);
            cols.RemoveAt(1);
            cols.RemoveAt(0);
            cols.RemoveAt(0);
            Assert.Equal(4, cols.Count);
            Assert.Equal("Column4", cols[0].ColumnName);
            Assert.Equal("Column5", cols[1].ColumnName);

            // Cannot find column 10.
            Assert.Throws <IndexOutOfRangeException>(() => cols.RemoveAt(10));
        }
Пример #2
0
        [Test]         // Add (String)
        public void Add3_ColumnName_Null()
        {
            DataTable            table = new DataTable();
            DataColumnCollection cols  = table.Columns;
            DataColumn           col;

            col = cols.Add((string)null);
            Assert.AreEqual(1, cols.Count, "#A1");
            Assert.AreEqual("Column1", col.ColumnName, "#A2");
            Assert.AreSame(table, col.Table, "#A3");

            col = cols.Add((string)null);
            Assert.AreEqual(2, cols.Count, "#B1");
            Assert.AreEqual("Column2", col.ColumnName, "#B2");
            Assert.AreSame(table, col.Table, "#B3");

            cols.RemoveAt(1);

            col = cols.Add((string)null);
            Assert.AreEqual(2, cols.Count, "#C1");
            Assert.AreEqual("Column2", col.ColumnName, "#C2");
            Assert.AreSame(table, col.Table, "#C3");

            cols.Clear();

            col = cols.Add((string)null);
            Assert.AreEqual(1, cols.Count, "#D1");
            Assert.AreEqual("Column1", col.ColumnName, "#D2");
            Assert.AreSame(table, col.Table, "#D3");
        }
Пример #3
0
        [Fact] // Add (String)
        public void Add3_ColumnName_Null()
        {
            DataTable            table = new DataTable();
            DataColumnCollection cols  = table.Columns;
            DataColumn           col;

            col = cols.Add((string)null);
            Assert.Equal(1, cols.Count);
            Assert.Equal("Column1", col.ColumnName);
            Assert.Same(table, col.Table);

            col = cols.Add((string)null);
            Assert.Equal(2, cols.Count);
            Assert.Equal("Column2", col.ColumnName);
            Assert.Same(table, col.Table);

            cols.RemoveAt(1);

            col = cols.Add((string)null);
            Assert.Equal(2, cols.Count);
            Assert.Equal("Column2", col.ColumnName);
            Assert.Same(table, col.Table);

            cols.Clear();

            col = cols.Add((string)null);
            Assert.Equal(1, cols.Count);
            Assert.Equal("Column1", col.ColumnName);
            Assert.Same(table, col.Table);
        }
Пример #4
0
        private void _btnDel_Click(object sender, System.EventArgs e)
        {
            DataColumnCollection c = _dt.Columns;
            var lastindex          = c.Count - 1;

            if (lastindex > -1)
            {
                c.RemoveAt(lastindex);
            }
        }
Пример #5
0
        public DataColumnCollection getColumnsWithoutIdentity()
        {
            DataColumnCollection columns        = model.getColumns();
            DataColumn           identityColumn = getIdentityColumn();

            for (int i = 0; i < columns.Count; ++i)
            {
                if (columns[i].ColumnName == identityColumn.ColumnName)
                {
                    columns.RemoveAt(i);
                }
            }

            return(columns);
        }
Пример #6
0
        public void Remove()
        {
            DataTable            Table = new DataTable("test_table");
            DataColumnCollection Cols  = Table.Columns;

            Cols.Add("test");
            Cols.Add("test2");
            Cols.Add("test3");
            Cols.Add("test4");

            Assert.Equal(4, Cols.Count);
            Cols.Remove("test2");
            Assert.Equal(3, Cols.Count);
            Cols.Remove("TEST3");
            Assert.Equal(2, Cols.Count);

            try
            {
                Cols.Remove("_test_");
                Assert.False(true);
            }
            catch (Exception e)
            {
                Assert.Equal(typeof(ArgumentException), e.GetType());
                // Never premise English.
                //Assert.Equal ("Column '_test_' does not belong to table test_table.", e.Message);
            }

            Cols.Add();
            Cols.Add();
            Cols.Add();
            Cols.Add();

            Assert.Equal(6, Cols.Count);
            Cols.Remove(Cols[0]);
            Cols.Remove(Cols[0]);
            Assert.Equal(4, Cols.Count);
            Assert.Equal("Column1", Cols[0].ColumnName);

            try
            {
                Cols.Remove(new DataColumn("Column10"));
                Assert.False(true);
            }
            catch (Exception e)
            {
                Assert.Equal(typeof(ArgumentException), e.GetType());
                // Never premise English.
                //Assert.Equal ("Cannot remove a column that doesn't belong to this table.", e.Message);
            }

            Cols.Add();
            Cols.Add();
            Cols.Add();
            Cols.Add();

            Assert.Equal(8, Cols.Count);
            Cols.RemoveAt(7);
            Cols.RemoveAt(1);
            Cols.RemoveAt(0);
            Cols.RemoveAt(0);
            Assert.Equal(4, Cols.Count);
            Assert.Equal("Column4", Cols[0].ColumnName);
            Assert.Equal("Column5", Cols[1].ColumnName);

            try
            {
                Cols.RemoveAt(10);
                Assert.False(true);
            }
            catch (Exception e)
            {
                Assert.Equal(typeof(IndexOutOfRangeException), e.GetType());
                // Never premise English.
                //Assert.Equal ("Cannot find column 10.", e.Message);
            }
        }
 public void RemoveAt(int index)
 {
     _columns.RemoveAt(index);
 }
Пример #8
0
 /// <summary>
 /// This sub removes the column specified by the given index from the collection.
 /// </summary>
 /// <param name="Index">Index of <see cref=" DASDataColumn "></see> object to be removed.</param>
 public void RemoveAt(int Index)
 {
     m_Columns.RemoveAt(Index);
 }
Пример #9
0
 public void RemoveAt(int index)
 {
     _collection.RemoveAt(index);
 }