RowHeader on DataGrid with captions - How?

Feb 5, 2011 at 8:23 PM

Hi, I am trying to create a RowHeader in a DataGrid with captions.
I tried different things, but nothing worked so far.

Anybody able to help?


Feb 7, 2011 at 6:06 AM

Have you looked at the examples (there are more than 50 of those)

Feb 7, 2011 at 9:12 AM

Yes I did, but there was no example regarding DataGrid and RowHeaders with captions.
By now I figured out how to do it, maybe this is of interest for someone else, so here's the code (modified version of another post I found here):

This is actually a combined example, because I needed kind of an row counter dislayed as well.

Imports SourceGrid.Cells
Imports SourceGrid

Public Class RowHeaderNumberColumn
    Inherits SourceGrid.DataGridColumn
    ''' <summary>
    ''' Constructor. Create a RowHeaderNumberColumn class.
    ''' </summary>
    Public Sub New(ByVal grid As DataGrid, ByVal headerText As String, ByVal prefix As String)
        MyBase.New(grid, New ColumnHeader(headerText), New Cell(), Nothing)
        Me.MaximalWidth = 35
        'Me.MinimalWidth = 30
        Me.DataCell.Model.ValueModel = New RowNumberValueModel(prefix)
        Me.DataCell.View = New SourceGrid.Cells.Views.RowHeader
        Me.AutoSizeMode = AutoSizeMode.EnableAutoSize
    End Sub

    Public Sub New(ByVal grid As SourceGrid.DataGrid)
        Me.New(grid, "No", String.Empty)
    End Sub

End Class

Public Class RowNumberValueModel
    Implements SourceGrid.Cells.Models.IValueModel
    Private _prefix As String
    Public Sub New(ByVal prefix As String)
        _prefix = prefix
    End Sub
    Public Function GetValue(ByVal cellContext As SourceGrid.CellContext) As Object Implements SourceGrid.Cells.Models.IValueModel.GetValue
        Return String.Format("{0}{1}", _prefix, cellContext.Position.Row)
    End Function

    Public Sub SetValue(ByVal cellContext As SourceGrid.CellContext, ByVal p_Value As Object) Implements SourceGrid.Cells.Models.IValueModel.SetValue
    End Sub
End Class

Insert this column with:
ConditionDataGrid.Columns.Insert(0, New RowHeaderNumberColumn(ConditionDataGrid, String.Empty, "C"))
ConditionDataGrid.FixedColumns = 1

Feb 8, 2011 at 8:50 AM

Btw, what do you mean by "caption"? IMO this is just a cell, which is used as header cell, and with simple text. Is this what you mean by caption?