Hello Friends,Infragistics wingrid offers formatting at column level.I want the same functionality at the cell level.My requirement is to NOT allow multiple decimal points in the wingrid cell. This is required at cell level and not at column level.Regards,Sid.
Hi Sid,
If your grid only contains numbers and string then you could put a 0 (zero) in every Column's Format property. That way any number will only be shown without any decimal places but strings will not be effected.
If you have other data types, such as dates, then you may need to consider a Custom Format Provider which checks the data type before applying formatting. I can let you have an example of this if it will help.
Cheers,
Andy.
Hi Andy,
Thanks for the prompt reply.Actually, I dont need formatting at the column level.I need formatting at the cell level. The cell should allowthe entry of numbers and decimal numbers(with one decimal point).I would be thankful if you could give me a sample code.Regards,Sid.
To the best of my knowledge there is no support for specific formatting at the Cell level (unless you get into OwnerDraw territory). My best suggestion would be to create a Custom Format Provider that you attach to every column.
You can examine the value that is being formatted and take the appropriate action. However, although you can determine the data type of the object to be formatted you cannot determine which Row, Column or Cell it is in. If your requirements are that you need this information to determine format then I'm afraid this solution may not work for you.
Regardless, here is some sample code that may allow you to achieve your goal:
public class CustomFormatProvider : IFormatProvider, ICustomFormatter
{
#region IFormatProvider Members
public object GetFormat(Type formatType)
if (formatType == typeof(ICustomFormatter))
return this;
else
return null;
}
#endregion
#region ICustomFormatter Members
public string Format(string format, object arg, IFormatProvider formatProvider)
try
// The most common types are here as an example. You only
// need to include the ones your grid will actually use.
// We'll start with noninteger numbers.
if (arg.GetType() == typeof(decimal))
return ((decimal)arg).ToString("0"); // Use the required format for decimals.
else if(arg.GetType() == typeof(float))
return ((float)arg).ToString("0"); // Use the required format for floats.
else if (arg.GetType() == typeof(double))
return ((double)arg).ToString("0"); // Use the required format for doubles.
// Then the integer.
else if (arg.GetType() == typeof(int))
return ((int)arg).ToString(); // Use the required format for integers.
// Now more complex types, such as DateTime. (You can also process your own objects in this way.)
else if (arg.GetType() == typeof(DateTime))
return ((DateTime)arg).ToShortDateString(); // Use the required format for dates.
// Everything else can just be returned as a string.
return arg.ToString();
catch (Exception ex) // If an error occurred return the message as the formatted string.
return ex.Message;
Once you've created the object you need to add an instance to every column in your grid that may need it:
CustomFormatProvider customProvider = new CustomFormatProvider();
foreach (UltraGridBand band in ultraGrid1.DisplayLayout.Bands)
foreach (UltraGridColumn column in band.Columns)
column.FormatInfo = customProvider;
Let me know if you need any further help.
I am looking for a similar formatting at cell level based on other column value. Please see this for more
http://community.infragistics.com/forums/t/65020.aspx
Have you got this solution?
Regards,
Satish.
I would be thankful if you could provide me with the code to use the owner draw functionality to allow only one decimal pointat the cell level and to allow only integers.Thanks,Sid.