RowNumber

May 19, 2009 at 2:36 PM

I'm trying to display a row number per row, probably in the RowHeader cell - can anyone tell me how to do this?  With the .net DataGridView I would possibly override the OnPaint method, but it doesn't quite work like that with SourceGrid...

Thanks.

Coordinator
May 19, 2009 at 5:22 PM

I would go this direction:

create a custom model, and create a custom view, and then us these two on the RowHeader cell

May 26, 2009 at 10:19 PM
Edited May 26, 2009 at 10:22 PM

You might try this as well.

grid[row, HEADER] = new SourceGrid.Cells.RowHeader(row.ToString());

 

May 27, 2009 at 8:54 AM

If you are using DataGrid you can use these classes to display rownumbers:


    public class NoColumn : SourceGrid.DataGridColumn
    {
        public NoColumn (DataGrid grid) : base(grid, new ColumnHeader("No"), new Cell(), null)
        {
            this.MaximalWidth = 80;
            this.MinimalWidth = 30;
            this.DataCell.Model.ValueModel = new NoColumnValueModel();

            this.HeaderCell.Controller.RemoveController(this.HeaderCell.Controller.FindController(typeof(SourceGrid.Cells.Controllers.SortableHeader)));
            this.AutoSizeMode = AutoSizeMode.EnableAutoSize;
        }
    }

    public class NoColumnValueModel : SourceGrid.Cells.Models.IValueModel
    {
        public object GetValue ( CellContext cellContext )
        {
            return string.Format("{0}.", cellContext.Position.Row);
        }

        public void SetValue ( CellContext cellContext, object p_Value )
        {
        }
    }


And than just use:

this.grid1.Columns.Insert(0, new NoColumn(this.grid1));