Hi all,
here's what I'm trying to do: I have a ultragrid, bound to a bindingsource, whose datasource is a datatable.
The data look like that:
...
I'd like to present it to the end user with some "clues" on the value cells.. for exemple, I'd like to show the difference in % from a year to another, or the difference of the value.. for exemple, instead of just showing "1000" for the row "2009"/Jan column, I'd like to say something like "+20%" or "+200€", change the appearance of the cell to reflect the fact that the value has grown ...
How could I achieve that using the ultragrid built-in features ? Do I have to add bands, or rows or columns (and use groups, row layout etc.) ? To I have to use a calcManager or loop through the rows and columns (the old way) to calculate those values ?
Could someone please point me in the right direction ? Any help would be greatly appreciated, thank you in advance !
François
Hi François,
What I would do is add some unbound columns to the grid. You could use the InitializeLayout event of the grid and add an unbound column to the band using band.Columns.Add. You could use the column.Header.VisiblePosition to place this column in between Jan and Feb.
To assign a value to this column, you could use UltraCalcManager and assign a formula to the column. Or, you could use the InitializeRow event and populate the value of the cell in code there.
InitializeRow is also a good place to apply a color to a cell based on a value in the cell or in the same row.
Thank you Mike for pointing me in this direction. Yes, it seems to be some possible solution, but my problem is that I will end up with 37 columns to display the results (1 for the year label, 1 value column by month + 1 for the growth percentage, by month + one for the delta, by month). I think the grid might become unreadable with so many columns.
The second problem I will face is that for the last row, there will be nothing to compare, and all cells will remain empty, wasting some precious pixels..
Another solution I was thinking of is programatically add rows to my datatable and make the calculation in the model layer. So I would get the 2 first rows in my example, and 2 more rows: one for the delta, one for the growth percentage, everything in only 13 columns. But since in every "Month" column, I will have 3 rows that represent money data and one that represent percent data, this lead me to another question:
How could I format cells differently in the same winGrid column ?
It seems somebody from Infragistics starts a thread to tell us the trick, but the thread says: "content coming soon" :-(
here is the thread: http://community.infragistics.com/winforms/articles/formatting-cells-differently-in-the-same-wingrid-column.aspx
Any chance to get some content soon ? Would make my day I think ..
Thank you in advance
Hi,
François said: Thank you Mike for pointing me in this direction. Yes, it seems to be some possible solution, but my problem is that I will end up with 37 columns to display the results (1 for the year label, 1 value column by month + 1 for the growth percentage, by month + one for the delta, by month). I think the grid might become unreadable with so many columns. The second problem I will face is that for the last row, there will be nothing to compare, and all cells will remain empty, wasting some precious pixels..
Okay... so where do you want to show this information? I assumed you wanted the extra info next to the cell it applies to. If you want it underneath the cell, you can do that with columns, too. You don't need to add extra rows to your data source. You can have columns stacked one atop the other by using groups or RowLayouts. So you could still use unbound columns and just position the growth percentage column for each month directly under the month instead of next to it.
This would still leave you with some empty cells in the last row, though.
François said:It seems somebody from Infragistics starts a thread to tell us the trick, but the thread says: "content coming soon" :-(
I'm not sure what's up with that article. But if you can tell me what you mean by "format", I'm sure I can point you in the right direction. Do you mean you just want to apply colors to the cell to indicate whether the value when up or down? To do that, you would use the InitializeRow event and apply an appearance to the cell based on the value. There are samples of this technique all over the place including one in the WinGrid Performance Guide
Hi Mike,
"I don't understand... why would you need to add rows to the data table?This is not at all what I was suggesting. " ..
I know you didn't :-)
Ok, forget about it, I will play with all the Layouts stuff to solve my problem. You can consider this thread as closed.
Thank you for your help, much appreciated
Cheers
I don't understand... why would you need to add rows to the data table?This is not at all what I was suggesting.
My suggestion is that you simply add columns, either to the data or to the grid that contain the values you want to show and position those columns underneath the existing columns so that each row of data occupies several rows on-screen. But it's still only one row in the data table.
Thank you for your followup,
I'm aware of the groups and RowLayouts capabilities of the winGrid, and use it, so that's the way I would have present the columns if I followed the solution you exposed in your previous post. So I agree 100%.
So what I had in mind was adding 2 rows to the datatable, where I would have store in the first of those two rows, the growth percentage, and the delta in the last rows (or the opposite, doen't matter). But as I tried to explain, this will leave me with a datatable with "mixed" content.. For example, in the "January" column:
YEAR | January | Feb |
2009 | 1000.00€ | 1000.00 € |
2008 | 800.00€ | 1050.00€ |
Delta | +200.00€ | -50.00€ |
Growth %| 20.00%| -5.00%|
So my needs are "formatting" cell content regarding the datataype .. the "January" column of the grid would have, at first look, a Format property set to C2 .. but the last row would be a problem, since it doen't represent money but percentage .
How can I use the InitializeRow event to format the cell content as percentage, only on this row ?
Hope I made myself clear %-)
Anyway, I'm still interested in a solution to format the value of a gridcell as Percentage in a gridcolumn that is format as "C2".
Thank you for your help,