.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How do you modify a cell style in a table style?

0 REPLIES 0
Reply
Message 1 of 1
Anonymous
599 Views, 0 Replies

How do you modify a cell style in a table style?

Does anybody know how to change a cell style in a table style? I would like to put a double line border around my table. I first tried using the .SetGridDoubleLineSpacing method of my table but found I was unable to to set the left and right side vertical borders as double lines. So I tried changing the cell style manually through the TABLESTYLE dialog. This does what I want but I would like to do this programmatically.

Here's my code so far...


Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Dim ed As Editor = doc.Editor
Dim tr As Transaction = doc.TransactionManager.StartTransaction
Dim pr As PromptPointResult = ed.GetPoint("Enter table insertion point: ")

If pr.Status = PromptStatus.OK Then
Dim doclock As DocumentLock = doc.LockDocument()

Using tr
Const tblstylename As String = "Chart Style"
Dim tblstyleID As ObjectId = ObjectId.Null

Dim sd As DBDictionary = tr.GetObject(db.TableStyleDictionaryId, OpenMode.ForRead)

If sd.Contains(tblstylename) Then
tblstyleID = sd.GetAt(tblstylename)
Else
Dim tblstyle As TableStyle = New TableStyle()

'Why doesn't this work?
tablestyle.IsTitleSuppressed = TRUE
tablestyle.IsHeaderSuppressed = TRUE

'What goes here to set borders?

sd.UpgradeOpen()
tblstyleID = sd.SetAt(tblstylename, tblstyle)
tr.AddNewlyCreatedDBObject(tblstyle, True)
sd.DowngradeOpen()
End If

Dim tbl As Table = New Table()

If tblstyleID = ObjectId.Null Then
'This should not happen, unless the above logic changes
tbl.TableStyle = db.Tablestyle
Else
tbl.TableStyle = tblstyleID
End If

tbl.NumRows = DataGridView.RowCount + 1 '.RowCount includes the empty row. +1 gives 2 rows for the headers.
tbl.NumColumns = 4
tbl.SetRowHeight(3)
tbl.SetColumnWidth(15)
tbl.Position = pr.Value

'Why doesn't IsTitle/HeaderSuppressed work in the table style?
tbl.SetCellStyle(0, -1, "Data")
tbl.SetCellStyle(1, -1, "Data")

tbl.SetTextHeight(0, 0, 1)
tbl.SetTextString(0, 0, "DESCRIPTOR")

tbl.MergeCells(New CellRange(0, 0, 1, 0))

tbl.SetAlignment(0, 0, CellAlignment.MiddleCenter)
tbl.SetTextHeight(0, 1, 1)
tbl.SetTextString(0, 1, "LOCATION" + System.Environment.NewLine + "Note: Points are reference only & may change do to CAD being master.")
tbl.MergeCells(New CellRange(0, 1, 0, 3))

tbl.SetTextHeight(1, 1, 1)
tbl.SetTextString(1, 1, "X")
tbl.SetAlignment(1, 1, CellAlignment.MiddleCenter)

tbl.SetTextHeight(1, 2, 1)
tbl.SetTextString(1, 2, "Y")
tbl.SetAlignment(1, 2, CellAlignment.MiddleCenter)

tbl.SetTextHeight(1, 3, 1)
tbl.SetTextString(1, 3, "Z")
tbl.SetAlignment(1, 3, CellAlignment.MiddleCenter)

Dim i As Integer
For i = 0 To DataGridView.RowCount - 2
tbl.SetTextHeight(i + 2, 0, 1)
tbl.SetTextString(i + 2, 0, DataGridView.Rows(i).HeaderCell.Value)
tbl.SetAlignment(i + 2, 0, CellAlignment.MiddleCenter)

If DataGridView.Rows(i).Cells(0).Value <> Nothing Then
tbl.SetTextHeight(i + 2, 1, 1)
tbl.SetTextString(i + 2, 1, DataGridView.Rows(i).Cells(0).Value)
tbl.SetAlignment(i + 2, 1, CellAlignment.MiddleCenter)
End If

If DataGridView.Rows(i).Cells(1).Value <> Nothing Then
tbl.SetTextHeight(i + 2, 2, 1)
tbl.SetTextString(i + 2, 2, DataGridView.Rows(i).Cells(1).Value)
tbl.SetAlignment(i + 2, 2, CellAlignment.MiddleCenter)
End If

If DataGridView.Rows(i).Cells(2).Value <> Nothing Then
tbl.SetTextHeight(i + 2, 3, 1)
tbl.SetTextString(i + 2, 3, DataGridView.Rows(i).Cells(2).Value)
tbl.SetAlignment(i + 2, 3, CellAlignment.MiddleCenter)
End If
Next

'Switched to using table styles. Left here for reference. Note setting horizontal works but vertical doesn't.
'tbl.SetGridDoubleLineSpacing(0, -1, GridLineType.OuterGridLines, 1)
'tbl.SetGridDoubleLineSpacing(tbl.NumRows - 1, -1, GridLineType.OuterGridLines, 1)
'tbl.SetGridDoubleLineSpacing(-1, 0, GridLineType.OuterGridLines, 1)
'tbl.SetGridDoubleLineSpacing(-1, tbl.NumColumns - 1, GridLineType.OuterGridLines, 1)
'tbl.SetGridLineStyle(0, -1, GridLineType.HorizontalTop, GridLineStyle.Double)
'tbl.SetGridLineStyle(tbl.NumRows - 1, -1, GridLineType.HorizontalBottom, GridLineStyle.Double)
'tbl.SetGridLineStyle(1, 1, GridLineType.VerticalLeft, GridLineStyle.Double)
'tbl.SetGridLineStyle(-1, tbl.NumColumns - 1, GridLineType.VerticalRight, GridLineStyle.Double)

tbl.GenerateLayout()

Dim bt As BlockTable = tr.GetObject(doc.Database.BlockTableId, OpenMode.ForRead)
Dim btr As BlockTableRecord = tr.GetObject(bt(BlockTableRecord.PaperSpace), OpenMode.ForWrite)

btr.AppendEntity(tbl)
tr.AddNewlyCreatedDBObject(tbl, True)
tr.Commit()
End Using
0 REPLIES 0

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost