向固定列中添加行号,比如Microsoft Excel,请使用OwnerDrawCell 时间来在固定列中画出数字并左对齐。
1. 添加下面的代码到Form_Load 事件中,触发OwnerDrawCell 事件:
• Visual Basic
Me.C1FlexGrid1.DrawMode = C1.Win.C1FlexGrid.DrawModeEnum.OwnerDraw |
• C#
this.c1FlexGrid1.DrawMode = C1.Win.C1FlexGrid.DrawModeEnum.OwnerDraw; |
2. 添加OwnerDrawCell 事件:
• Visual Basic
Private Sub C1FlexGrid1_OwnerDrawCell(ByVal sender As Object, ByVal e As C1.Win.C1FlexGrid.OwnerDrawCellEventArgs) Handles C1FlexGrid1.OwnerDrawCell If e.Row >= Me.C1FlexGrid1.Rows.Fixed And e.Col = Me.C1FlexGrid1.Cols.Fixed - 1 Then Dim rowNumber As Integer = e.Row - Me.C1FlexGrid1.Rows.Fixed + 1 e.Text = rowNumber.ToString() End If End Sub |
• C#
private void c1FlexGrid1_OwnerDrawCell(object sender, C1.Win.C1FlexGrid.OwnerDrawCellEventArgs e) { if ((e.Row >= this.c1FlexGrid1.Rows.Fixed) & (e.Col == (this.c1FlexGrid1.Cols.Fixed - 1))) { e.Text = ((e.Row - this.c1FlexGrid1.Rows.Fixed) + 1).ToString(); } } |
行号出现在第一列,它是固定的并左对齐,就像Microsoft Excel一样。