Syncfusion GridControl - Create extended Custom Column Properties
Syncfusion GridControl - Create extended Custom Column Properties
When you need some additional information stored. Which can used in the runtime for saving or validating. you will need to have extended column properties. With we can some additional properties in GridControl which can be accessed in code.
Such as is the column required, Custom Error Message , DataType, Fieldname in database which will be linked to column and so on.
created a property which take information as per column index
namespace ATS.WinForms.Controls
{
public partial class Grid : GridControl
{
[Description("Set Grid Column Properties"), Category("ATS")]
[EditorAttribute(typeof(System.ComponentModel.Design.ArrayEditor), typeof(System.Drawing.Design.UITypeEditor))]
public GridColumnProperties[] ColumnProperties
{
get
{
if (_ColumnProperties == null)
{
_ColumnProperties = new GridColumnProperties[0];
}
return _ColumnProperties;
}
set
{
_ColumnProperties = value;
}
}
}
}
namespace ATS.WinForms.Controls
{
public class GridColumnProperties
{
public int ColumnIndex { get; set; }
public string FieldName { get; set; }
public bool IsRequired { get; set; }
public bool IsUpdatable { get; set; }
public bool IsUnqiue { get; set; }
public string GroupUnqiueKey { get; set; }
public FieldDataType DataType { get; set; }
public bool IsForeignKey { get; set; }
public string ErrorMessage { get; set; }
public bool IsEmptySaveDBNull { get; set; }
public string DateTimeFormat { get; set; }
}
}
public partial class Grid : GridControl
{
[Description("Set Grid Column Properties"), Category("ATS")]
[EditorAttribute(typeof(System.ComponentModel.Design.ArrayEditor), typeof(System.Drawing.Design.UITypeEditor))]
public GridColumnProperties[] ColumnProperties
{
get
{
if (_ColumnProperties == null)
{
_ColumnProperties = new GridColumnProperties[0];
}
return _ColumnProperties;
}
set
{
_ColumnProperties = value;
}
}
}
}
namespace ATS.WinForms.Controls
{
public class GridColumnProperties
{
public int ColumnIndex { get; set; }
public string FieldName { get; set; }
public bool IsRequired { get; set; }
public bool IsUpdatable { get; set; }
public bool IsUnqiue { get; set; }
public string GroupUnqiueKey { get; set; }
public FieldDataType DataType { get; set; }
public bool IsForeignKey { get; set; }
public string ErrorMessage { get; set; }
public bool IsEmptySaveDBNull { get; set; }
public string DateTimeFormat { get; set; }
}
}
How to use the properties from logic
for (int k = 0; k < _Grid.ColumnProperties.Length; k++)
{
GridColumnProperties gridColumnProperties2 = new GridColumnProperties();
gridColumnProperties2 = _Grid.ColumnProperties[k];
if (gridColumnProperties2 == null || !gridColumnProperties2.IsUnqiue)
{
continue;
}
for (int l = 1; l <= _Grid.RowCount; l++)
{
if (gcp.DataType == FieldDataType.String)
{
string text = '' // read cell value ;
return "'" + text.ToString().Replace("'", "''") + "'";
}
}
}
Comments
Post a Comment