My understanding you use InsertRows & InsertColumns
You can set the settings for a row and use InsertRowsAndInherit(index where to start, index to copy settings, # of rows)
I have no idea why this keeps making the last row a title.
I used Tuples just messing around no real reason
[CommandMethod("CreateSymbolLegend")]
public void CreateSymbolLegend()
{
List<Tuple<ObjectId, string, string>> blockinfo = new List<Tuple<ObjectId, string, string>>();
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
using (Transaction trx = db.TransactionManager.StartTransaction())
{
BlockTable bt = db.BlockTableId.GetObject(OpenMode.ForRead) as BlockTable;
BlockTableRecord btrMs = (BlockTableRecord)bt[BlockTableRecord.ModelSpace].GetObject(OpenMode.ForRead);
foreach (ObjectId objId in bt)
{
BlockTableRecord btr = trx.GetObject(objId, OpenMode.ForRead) as BlockTableRecord;
if (btr.IsLayout) continue;
blockinfo.Add(Tuple.Create(btr.ObjectId, btr.Name, btr.Comments));
}
Tuple<ObjectId, string, string>[] blockArr = blockinfo.ToArray();
Table tbl = new Table();
tbl.TableStyle = db.Tablestyle;
tbl.Position = Point3d.Origin;
tbl.InsertRows(0, 1, 1);
tbl.Rows[0].Style = "Data";
tbl.InsertRowsAndInherit(1, 0, blockArr.Length - 2);
tbl.InsertColumns(0, 1, 1);
for (int i = 0; i < blockArr.Length; i++)
{
tbl.Cells[i, 0].Contents.Add();
tbl.Cells[i, 0].Contents[0].BlockTableRecordId = blockArr[i].Item1;
tbl.Cells[i, 1].Value = blockArr[i].Item3;
}
tbl.GenerateLayout();
btrMs.UpgradeOpen();
btrMs.AppendEntity(tbl);
trx.AddNewlyCreatedDBObject(tbl, true);
trx.Commit();
}
}