Message 1 of 1
Something to know when working with Tables
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have this table
Which has rows 1 through 5. Which while programming you would think would be 0 through 4.
But when using this testing method
[CommandMethod(nameof(TableTest1))]
public void TableTest1()
{
ObjectId tableId = Active.Editor.GetUser<Table>("\nSelect Table: ");
using (Transaction tr = tableId.Database.TransactionManager.StartTransaction())
using(Table table = tr.GetObject(tableId, OpenMode.ForWrite, false, true) as Table)
{
try
{
int numRows = table.Rows.Count;
int bottomRow = table.Cells.BottomRow;
table.InsertRows(bottomRow, 0.5, 1);
tr.Commit();
}
catch(Exception ex)
{
tr.Abort();
}
}
}
numRows comes back as 5, as expected.
bottomRow comes back as 4, as expected.
Here is where I got confused and thought I would share.
Running InsertRow like above, the new row is placed at the index given as the first param. So what was the bottom row gets shifted down, or another way of saying it is the new row is "placed on top" of the last row.
I found this confusing, as I thought I would be inserting rows under the index given. Just thought I would share this incase anyone comes across a similar confusing in the future.