Custom-drawn histogram based on cell value ?

May 19, 2009 at 3:46 PM
Edited May 19, 2009 at 3:47 PM

Hello,

first I must say I'm very positively impressed by SourceGrid for the moment! So thanks for your work.

I have two questions for the moment. First question: we need to draw a histogram that represents the underlying number (ie: draw a full horizontal bar if the value is 1.0, draw a half-full bar if the value is 0.5 etc). I'm not sure what the recommended way is. I tried:

  • overriding OnDrawContent in Views.Cell (but I don't have access to the value there)
  • overriding PrepareVisualElementImage (I have the value there, but I'm not sure how to impact the drawing)
  • starting from the sample 3 RoundView (but I can't find a way to get the value from the background either)

I'm pretty sure there is an easy way somewhere, where I would have access to the float value as well as Graphics.FillRectangle. What would be the recommended option ?

Second question: I saw that there is a built-in way to format percentages:

      cell.View = new SourceGrid.Cells.Views.Cell { Font = BuildFont(form.Font, 0.9, form.Font.Style), ForeColor = Color.Gray};
      var editor = new SourceGrid.Cells.Editors.TextBox(typeof(double));
      editor.TypeConverter = new DevAge.ComponentModel.Converter.PercentTypeConverter(typeof(double));
      cell.Editor = editor;

I was intrigued to see I needed an "editor" here. Is there a way to just format it without allowing edition (like a custom view ?) ? Or is using this code the recommended way to go for formats ?

thanks for your work and support!

-- Thibaut

Coordinator
May 25, 2009 at 7:26 AM

1. Try overriding IView.DrawCell method, it has a param CellContext, and CellContext has a property "DisplayText".

2. I depends how you intend to use percent formatter. I am no expert in this area, but i believe it should be possible to format without allowing edition.