Hi,
I try to use ultraChart-controls in rows (about 5.000) of an ultragrid. The charts are computed in the InitializeRow-event of the grid, which calls the following method:
Private Sub SetChartControl(ByRef pRow As UltraGridRow, pValueList As List(Of Decimal)) Dim ucce As New Infragistics.Win.UltraWinEditors.UltraControlContainerEditor() Dim dt As New DataTable dt.Columns.Add("1", GetType(Decimal)) dt.Columns.Add("2", GetType(Decimal)) dt.Columns.Add("3", GetType(Decimal)) dt.Rows.Add(pValueList.Item(0), pValueList.Item(1), pValueList.Item(3)) Dim uc As New Infragistics.Win.UltraWinChart.UltraChart() uc.ChartType = ChartType.LineChart uc.DataSource = dt uc.DataBind() ucce.RenderingControl = ucpRow.Cells("Orders").EditorComponent = ucce End Sub
Private Sub SetChartControl(ByRef pRow As UltraGridRow, pValueList As List(Of Decimal))
Dim ucce As New Infragistics.Win.UltraWinEditors.UltraControlContainerEditor()
Dim dt As New DataTable dt.Columns.Add("1", GetType(Decimal)) dt.Columns.Add("2", GetType(Decimal)) dt.Columns.Add("3", GetType(Decimal)) dt.Rows.Add(pValueList.Item(0), pValueList.Item(1), pValueList.Item(3))
Dim uc As New Infragistics.Win.UltraWinChart.UltraChart() uc.ChartType = ChartType.LineChart uc.DataSource = dt uc.DataBind()
ucce.RenderingControl = ucpRow.Cells("Orders").EditorComponent = ucce
End Sub
This leads to memory problems (SystemOutOfMemoryExceptions).What's the best way to get the desired result without the memory leaks?
Thank you very much.Regards, Marco
Well... it's no surprise that this leads to memory issues. You are creating a new chart for every cell in the column and more than that, because you will end up creating and recreating a chart for the same cell every time a value in any row changes.
What you should do is store the DataTable in the grid cell as the cell's Value. then you can use a single UltraControlContainer editor and a single chart control for the entire column. This is what the UltraControlContainerEditor sample included with NetAdvantage does.
Hi Mike,
thank you! That worked.
Now I have two additional questions, regarding your solution:1) Is it possible to have some of the rows to not show the chart in the cell? Setting the EditorComponent = nothing for these cells did not work.2) How to paint the charts in the cells in different colors? Some of the charts (a linechart with only one line) in the cells should be in green, others in red, depending on values of other cells of the row. Is that possible?
RegardsMarco
Hi Marco,
Ah, okay. Those both sound look good solutions. I didn't think of using two UltraControlContainerEditors, because I gathered (incorrectly) from your post that you needed a very large range of different colors. I didn't realize you only needed two. :)
Thank you, Mike.
With your help I was able to get the last 2 points work, too.
1) I used an empty value and set the line-chart to not show empty values to suppress the chart in some cells.2) As I only needed two different colors (green, red) I placed two different UltraCharts and EditorControls on the form and in the InitializeRow-event I assign one of the EditorComponents (depending on the cell-value) to the cell.
Everything works now as it should. Thanks for your help.
Regards,Marco
1) Setting the EditorControl to Nothing on the cell won't do anything, because the cell's EditorContorl is already nothing. When the EditorControl on the cell is nothing, the cell falls back to using the column's editor. So in order to make this work, you have to set the EditorControl to something else - some other editor control that will override the UltraControlContainerEditor. Which one you use depends on what you want the cell to do when there's no chart. If you just want to show nothing, then I recommend using an UltraPictureBox control. That will give you a nice blank read-only cell.
2) This could be done, but it would be very tricky. I don't think you can do this using the UltraControlContainerEditor component, you would have to use the editor itself and override certain methods to apply appearances to your RenderingControl (chart).
I might be able to whip up a sample for you. But I need more information. For example, where are you getting the colors from? Some other cell in the row? Is it based on the data in the chart?