回复 4楼Alice的帖子
- public class ExcelRow : C1.Silverlight.FlexGrid.GroupRow
- {
- # region 私有变量
- // 存储该行对应列的单元格样式
- private Dictionary<Column, CellStyle> m_CellStyles;
- # endregion
- # region 方法
- public ExcelRow(ExcelRow excelRow)
- {
- if (excelRow != null && excelRow.Grid != null)
- {
- foreach (Column column in excelRow.Grid.Columns)
- {
- CellStyle cellStyle = excelRow.GetCellStyle(column);
- if (cellStyle != null)
- {
- this.SetCellStyle(column, cellStyle.Clone());
- }
- }
- }
- }
- public ExcelRow()
- : this(null)
- { }
- /// <summary>
- /// 设置该行里某列的单元格样式
- /// </summary>
- /// <param name="col">某列</param>
- /// <param name="style">单元格样式</param>
- public void SetCellStyle(Column col, CellStyle style)
- {
- if (style != GetCellStyle(col))
- {
- if (m_CellStyles == null)
- {
- m_CellStyles = new Dictionary<Column, CellStyle>();
- }
- m_CellStyles[col] = style;
- if (Grid != null)
- {
- // 在指定单元格内重新绘制元素
- Grid.Invalidate(new CellRange(this.Index, col.Index));
- }
- }
- }
- /// <summary>
- /// 获取该行里某列的单元格样式
- /// </summary>
- /// <param name="col">某列</param>
- /// <returns>单元格样式</returns>
- public CellStyle GetCellStyle(Column col)
- {
- CellStyle cellStyle = null;
- if (m_CellStyles != null)
- {
- m_CellStyles.TryGetValue(col, out cellStyle);
- }
- return cellStyle;
- }
- # endregion
- }
复制代码 在C1FlexGrid初始化添加行时,采用- ExcelRow newRow = new ExcelRow();
- newRow.Height = row.Height;// 行高
- newRow.IsReadOnly = true;
- grid.Rows.Add(newRow);
复制代码 |