cart: empty [ Login ]

Change Background color of cell/row in DxfTable

1 
Lalit Aggarwal
2/10/2016 2:29 PM
How to change the background color of cell/row in DxfTable. I have tried but it is not reflected in the generated Dxf file. Sample Source Code:
C# Code:
DxfModel model = new DxfModel(DxfVersion.Dxf21); DxfTableStyle tableStyle = new DxfTableStyle("Double bordered"); tableStyle.DataCellStyle.SetAllBordersBorderType(BorderType.Double); tableStyle.DataCellStyle.SetAllBordersColor(Colors.Green); tableStyle.TitleCellStyle.SetAllBordersBorderType(BorderType.Double); tableStyle.HeaderCellStyle.SetAllBordersBorderType(BorderType.Double); tableStyle.HeaderCellStyle.ContentColor = Colors.Blue; tableStyle.TableCellStyle.OverrideBackColor = true; tableStyle.TableCellStyle.BackColor = Colors.Red; //tableStyle.DataCellStyle.OverrideBackColor = true; //tableStyle.DataCellStyle.BackColor = Colors.Red; model.TableStyles.Add(tableStyle); DxfTable table = new DxfTable(tableStyle); table.InsertionPoint = new Point3D(0d, 10d, 0d); table.RowCount = 6; table.ColumnCount = 3; foreach (DxfTableColumn column in table.Columns) { column.Width = 8d; } table.Rows[0].Cells[0].Contents.Add(new DxfValueFormat.String(), "The table title"); table.Rows[1].Cells[0].Contents.Add(new DxfValueFormat.String(), "Column 1 Header"); table.Rows[1].Cells[1].Contents.Add(new DxfValueFormat.String(), "Column 2 Header"); table.Rows[1].Cells[2].Contents.Add(new DxfValueFormat.String(), "Column 3 Header"); table.Rows[2].Cells[0].Contents.Add(new DxfValueFormat.String(), "Text"); //table.Rows[2].Cells[0].CellStyleOverrides.BackColor = Colors.Red; table.Rows[4].Cells[0].Contents.Add(DxfValueFormat.Date.CreateRegionalLongDateTime(), DateTime.Now); table.Rows[5].Cells[0].Contents.Add(new DxfValueFormat.DecimalNumber(LinearUnitFormat.Decimal), 123.45d); // Merge the title row cells. table.MergedCellRanges.Add(new DxfTableCellRange(0, 0, 0, 2)); // This demonstrates a merged cell block of 3 by 2 cells. table.MergedCellRanges.Add(new DxfTableCellRange(2, 0, 3, 2)); model.Entities.Add(table); DxfWriter.Write("Table Example.dxf", model);
Thanks, Lalit Aggarwal
Wout
2/11/2016 4:50 PM
Hi, There was a bug, it's now fixed, please download the latest CadLib 4.0 version. Note that you can't set the TableCellStyle.BackColor, because the property is not used. You can set the BackColor for the DataCellStyle, HeaderCellStyle and TitleCellStyle though. See modified sample below:
C# Code:
DxfModel model = new DxfModel(DxfVersion.Dxf21); DxfTableStyle tableStyle = new DxfTableStyle("Double bordered"); tableStyle.DataCellStyle.SetAllBordersBorderType(BorderType.Double); tableStyle.DataCellStyle.SetAllBordersColor(Colors.Green); tableStyle.DataCellStyle.BackColor = Colors.Blue; tableStyle.TitleCellStyle.SetAllBordersBorderType(BorderType.Double); tableStyle.TitleCellStyle.BackColor = Colors.Red; tableStyle.HeaderCellStyle.SetAllBordersBorderType(BorderType.Double); tableStyle.HeaderCellStyle.ContentColor = Colors.Blue; tableStyle.HeaderCellStyle.BackColor = Colors.Green; // Setting the BackColor of the TableCellStyle is not supported. //tableStyle.TableCellStyle.BackColor = Colors.Red; model.TableStyles.Add(tableStyle); DxfTable table = new DxfTable(tableStyle); table.InsertionPoint = new Point3D(0d, 10d, 0d); table.RowCount = 6; table.ColumnCount = 3; foreach (DxfTableColumn column in table.Columns) { column.Width = 8d; } table.Rows[0].Cells[0].Contents.Add(new DxfValueFormat.String(), "The table title"); table.Rows[1].Cells[0].Contents.Add(new DxfValueFormat.String(), "Column 1 Header"); table.Rows[1].Cells[1].Contents.Add(new DxfValueFormat.String(), "Column 2 Header"); table.Rows[1].Cells[2].Contents.Add(new DxfValueFormat.String(), "Column 3 Header"); table.Rows[2].Cells[0].Contents.Add(new DxfValueFormat.String(), "Text"); table.Rows[2].Cells[0].CellStyleOverrides.BackColor = Colors.Orange; table.Rows[4].Cells[0].Contents.Add(DxfValueFormat.Date.CreateRegionalLongDateTime(), DateTime.Now); table.Rows[5].Cells[0].Contents.Add(new DxfValueFormat.DecimalNumber(LinearUnitFormat.Decimal), 123.45d); // Merge the title row cells. table.MergedCellRanges.Add(new DxfTableCellRange(0, 0, 0, 2)); // This demonstrates a merged cell block of 3 by 2 cells. table.MergedCellRanges.Add(new DxfTableCellRange(2, 0, 3, 2)); model.Entities.Add(table); DxfWriter.Write(@"C:\support\Table Example.dxf", model); DwgWriter.Write(@"C:\support\Table Example.dwg", model);
- Wout
1