Code Red > .NET

Tables and TableStyles

(1/1)

tjr:
Has anyone done any work with tables and table styles? In a post a few weeks ago I posted some trouble I was having with a table I am creating via code. Now I'm not marking anything as "header" so all rows are data. However when I enable the repeat top row property on a table I am getting two rows across when I break the table. I tried marking the first row as a header but then I don't get the top row on the second table in the break.

Any thoughts?

tjr:
I'm losing my mind here with this issue. Here is the code I'm using to draw a table and no matter what the second row comes in as a "Header". Anyone see anything obvious? I'm grabbing all my values from a dataset in case it wasn't obvious.
Note: This has some ugliness to it and I need to cleaned it up after I get the functionality I want. I had converted some Boo code I did to C# using reflector. Not the prettiest output in the world, but it works.


--- Code: ---       public void DrawBOM()
        {
            Document mdiActiveDocument = Application.DocumentManager.MdiActiveDocument;
            Database database = mdiActiveDocument.Database;
            Editor editor = mdiActiveDocument.Editor;
            System.Data.DataTable objBom = new BOMCombiner(this.bomData).getBomTable2();
            int dimScale = int.Parse(Application.GetSystemVariable("DIMSCALE").ToString());
            DataSet set = new DataSet();
            set.Tables.Add(objBom);
            this.splitBoms = set;

            int currentTableLoc = 0;
            int bomTableCount = this.splitBoms.Tables.Count;
            if (bomTableCount < 0)
            {
                throw new ArgumentOutOfRangeException("max");
            }
            while (currentTableLoc < bomTableCount)
            {
                int TableLoc = currentTableLoc;
                currentTableLoc++;
                PromptPointResult point = editor.GetPoint("\nEnter insertion point: ");
                Table bmTable = new Table();
                bmTable.TableStyle = database.Tablestyle;
                bmTable.IsTitleSuppressed = true;
                bmTable.IsHeaderSuppressed = false;
                bmTable.NumRows = this.splitBoms.Tables[TableLoc].Rows.Count + 1;
                bmTable.NumColumns = this.splitBoms.Tables[TableLoc].Columns.Count;
                for (int row = 0; row < bmTable.NumRows; row++)
                {
                    bmTable.SetCellStyle(row, 0, "Data");
                }
                int colCount = this.splitBoms.Tables[TableLoc].Columns.Count;
                int qtyCols = colCount - 7;
                bmTable.SetColumnWidth(colCount - 1, 0.5 * dimScale);
                bmTable.SetColumnWidth(colCount - 2, 1.5 * dimScale);
                bmTable.SetColumnWidth(colCount - 3, 0.75 * dimScale);
                bmTable.SetColumnWidth(colCount - 4, 0.75 * dimScale);
                bmTable.SetColumnWidth(colCount - 5, (double) (5 * dimScale));
                bmTable.SetColumnWidth(colCount - 6, 0.6 * dimScale);
                bmTable.SetColumnWidth(colCount - 7, 1.75 * dimScale);
                for (int col=0; col < qtyCols; col++)
                {
                    bmTable.SetColumnWidth(col, 0.5 * dimScale);
                }

                const CellStates cState = CellStates.ContentReadOnly;

                bmTable.Position = point.Value;
                bmTable.SetRowHeight(0.25 * dimScale);
                bmTable.SetTextHeight(0, colCount - 1, 0.1 * dimScale);
                bmTable.SetTextString(0, colCount - 1, "KSP");
                bmTable.SetCellState(0, colCount - 1, cState);
                bmTable.SetTextHeight(0, colCount - 2, 0.1 * dimScale);
                bmTable.SetTextString(0, colCount - 2, "REMARK");
                bmTable.SetTextHeight(0, colCount - 3, 0.1 * dimScale);
                bmTable.SetTextString(0, colCount - 3, "WID.");
                bmTable.SetCellState(0, colCount - 3, cState);
                bmTable.SetTextHeight(0, colCount - 4, 0.1 * dimScale);
                bmTable.SetTextString(0, colCount - 4, "LEN.");
                bmTable.SetCellState(0, colCount - 4, cState);
                bmTable.SetTextHeight(0, colCount - 5, 0.1 * dimScale);
                bmTable.SetTextString(0, colCount - 5, "DESCRIPTION");
                bmTable.SetCellState(0, colCount - 5, cState);
                bmTable.SetTextHeight(0, colCount - 6, 0.1 * dimScale);
                bmTable.SetTextString(0, colCount - 6, "ITEM");
                bmTable.SetCellState(0, colCount - 6, cState);
                bmTable.SetTextHeight(0, colCount - 7, 0.1 * dimScale);
                bmTable.SetTextString(0, colCount - 7, "PART/CAT. No.");
                bmTable.SetCellState(0, colCount - 7, cState);
                for (int col = 0; col < qtyCols; col++)
                {
                    bmTable.SetTextHeight(0,col, 0.1 * dimScale);
                    bmTable.SetTextString(0,col, "QTY. " + objBom.Columns[col].ColumnName.Remove(0,3));
                    bmTable.SetCellState(0, col, cState);
                }
               

                int x = 1;
                foreach (DataRow dr in this.splitBoms.Tables[TableLoc].Rows)
                {
                    bmTable.SetCellStyle(x, colCount - 1, "Data");
                    if (dr["ksp"].ToString() == "True")
                    {
                        bmTable.SetTextString(x, colCount - 1, "*");
                    }
                    else
                    {
                        bmTable.SetTextString(x, colCount - 1, "");
                    }
                    bmTable.SetTextHeight(x, colCount - 1, 0.125 * dimScale);
                    bmTable.SetCellState(x, colCount - 1, cState);
                    bmTable.SetTextString(x, colCount - 2, dr["remark"].ToString());
                    bmTable.SetTextHeight(x, colCount - 2, 0.125 * dimScale);
                    bmTable.SetCellState(x, colCount - 2, cState);
                    if (dr["bwidth"].ToString() == "0")
                    {
                        bmTable.SetTextString(x, colCount - 3, "");
                    }
                    else
                    {
                        Fraction wfrac = new Fraction(double.Parse(dr["bwidth"].ToString()));
                        bmTable.SetTextString(x, colCount - 3, wfrac.ToString() + '"');
                    }
                    bmTable.SetTextHeight(x, colCount - 3, 0.125 * dimScale);
                    bmTable.SetCellState(x, colCount - 3, cState);
                    if (dr["blength"].ToString() == "0")
                    {
                        bmTable.SetTextString(x, colCount - 4, "");
                    }
                    else
                    {
                        Fraction lfrac = new Fraction(double.Parse(dr["blength"].ToString()));
                        bmTable.SetTextString(x, colCount - 4, lfrac.ToString() + '"');
                    }
                    bmTable.SetTextHeight(x, colCount - 4, 0.125 * dimScale);
                    bmTable.SetCellState(x, colCount - 4, cState);
                    bmTable.SetTextString(x, colCount - 5, dr["description"].ToString().ToUpper());
                    bmTable.SetTextHeight(x, colCount - 5, 0.125 * dimScale);
                    bmTable.SetCellState(x, colCount - 5, cState);
                    bmTable.SetTextString(x, colCount - 6, dr["partno"].ToString());
                    bmTable.SetTextHeight(x, colCount - 6, 0.125 * dimScale);
                    bmTable.SetCellState(x, colCount - 6, cState);
                    bmTable.SetTextString(x, colCount - 7, dr["catalogno"].ToString());
                    bmTable.SetTextHeight(x, colCount - 7, 0.125 * dimScale);
                    bmTable.SetCellState(x, colCount - 7, cState);
                   
                    for (int col = 0; col < qtyCols; col++)
                    {
                        bmTable.SetTextString(x, col, dr[col].ToString());
                        bmTable.SetTextHeight(x, col, 0.125 * dimScale);
                        bmTable.SetCellState(x, col, cState);
                    }
                    x++;
                }


                // Enable Table breaking
                bmTable.BreakEnabled = true;
                bmTable.BreakFlowDirection = TableBreakFlowDirection.Left;
                bmTable.BreakOptions = TableBreakOptions.AllowManualHeights | TableBreakOptions.AllowManualPositions | TableBreakOptions.RepeatTopLabels;

                Autodesk.AutoCAD.DatabaseServices.Transaction transaction = mdiActiveDocument.TransactionManager.StartTransaction();
                BlockTable table3 = (BlockTable) transaction.GetObject(mdiActiveDocument.Database.BlockTableId, OpenMode.ForWrite);
                BlockTableRecord record = (BlockTableRecord) transaction.GetObject(table3[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
                record.AppendEntity(bmTable);
                transaction.AddNewlyCreatedDBObject(bmTable, true);
                transaction.Commit();
                record.Dispose();
                table3.Dispose();
                transaction.Dispose();
            }
        }

--- End code ---

T.Willey:
I don't see a way with code.  I did notice that you can pick which style of rows you want with the command, but all I see is a way to get the row style not set it with code.

T.Willey:

--- Quote from: T.Willey on October 27, 2008, 06:40:03 PM ---I don't see a way with code.  I did notice that you can pick which style of rows you want with the command, but all I see is a way to get the row style not set it with code.

--- End quote ---
This is not the problem.  If you suppress the title, then the next row is a header row, then the one after is a data row.  There must be some other switch that tells it which rows to copy.  I'm not sure how to find it unless you put the same two tables in; one per command, and one per code, and compare the dxf codes to see where they differ.  Then maybe that would give you a good point to hone in on.

Navigation

[0] Message Index

Go to full version