Hi!
I have the following issue - the datasource for my ultragrid is a database table having a column called "quantity", of type integer.
I want that if the quantity is 0, do display in the grid "none", but i get a type conversion error, and nothing is displayed in that cell.
How could I solve this issue ?
Thanks!
What did you try to do when you got the error?
You can solve it in several ways, but I think the simplest one is to add a ValueList with one item with "none" as text and zero as value.
I was trying to do
cell.value = "***" ;
where cell belonged to a integer column.
I'm not sure that a value list is the best solution, because in some cases I establish wether is 0 or "***" based on some special conditions.
Can't I change a cell type..or format?
Your DataFilter is never settings args.Handled = true.
Thanks Brian!
I've implemented this filter :
using System;using System.Collections.Generic;using System.Linq;using System.Text;using Infragistics.Win;namespace ModiasNT.Modules.Views.EditorFilters{ class NoQtyFilter : Infragistics.Win.IEditorDataFilter { object Infragistics.Win.IEditorDataFilter.Convert(Infragistics.Win.EditorDataFilterConvertArgs args) { switch (args.Direction) { case ConversionDirection.OwnerToEditor: switch (Convert.ToString(args.Value)) { case "0": return "***"; case "%": return "***"; case "0%": return "***"; case "": return "***"; default: return args.Value; } case ConversionDirection.EditorToOwner: return args.Value; break; case ConversionDirection.EditorToDisplay: switch (Convert.ToString(args.Value)) { case "0": return "***"; case "%": return "***"; case "0%": return "***"; case "": return "***"; default: return args.Value; } case ConversionDirection.DisplayToEditor: return args.Value; break; } throw new Exception("Invalid value"); } }}
But somehow it doesn't do the job...I get the same "0" or no value.
Any ideea why ?
Actually using a ValueList to solve this problem is a bad idea, unless your quantity field has a relatively small number of possible values. ValueLists are used to present human readable values to a user while allowing the underlying value to remain compatible with the data. For example, if you had a column for shipper, and the values were 1=UPS, 2=USPS, 3=FEDEX, you would add three items to your value list, with the numbers as the DataValue and the names as the DisplayText. Then the user would see 'UPS', ands when they select that item the integral value 1 would be assigned to the cell.
One solution to your problem would be to implement the IEditorDataFilter interface (which you would then assign to the column's Editor.DataFilter property). In this case you would code it so that a value of zero is converted to "none", and vice versa. There is a KB article that demonstrates this concept using boolean values, but the approach is the same.
Note that UltraGridColumn exposes a NullText property, which allows to to display a value like "none" when the value is null, which solves the similar problem of displaying something when there is no value at all.
Thanks Amir!
ulgSupplierGrid.DisplayLayout.ValueLists.Add("supplier");ulgSupplierGrid.DisplayLayout.ValueLists.Add("supplier").ValueListItems.Add(0, "none");
cell.ValueList = ulgSupplierGrid.DisplayLayout.ValueLists["supplier"];cell.Value = 0;
I'm using this code, but instead of "none" I get the 0 .
What am I doing wrong?
If you want to show "none", just set the cell value to zero and it will show "none".