Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,32 @@
# How to create custom column in winforms datagrid?
This repositories contains the samples to create custom column in winforms datagrid
# How to customize the column format in WinForms DataGrid (SfDataGrid)

[SfDataGrid](https://help.syncfusion.com/cr/windowsforms/Syncfusion.WinForms.DataGrid.SfDataGrid.html?_ga=2.113253391.967019853.1668146580-766490130.1650530957&_gl=1*4g8syb*_ga*NzY2NDkwMTMwLjE2NTA1MzA5NTc.*_ga_WC4JKKPHH0*MTY2ODE1ODI2OC4yOTcuMS4xNjY4MTY1NDc3LjAuMC4w) allows you to create and assign custom format for the columns through the [IDataGridFormatProvider](https://help.syncfusion.com/cr/windowsforms/Syncfusion.WinForms.DataGrid.IDataGridFormatProvider.html?_ga=2.154793776.967019853.1668146580-766490130.1650530957&_gl=1*kfpypb*_ga*NzY2NDkwMTMwLjE2NTA1MzA5NTc.*_ga_WC4JKKPHH0*MTY2ODE1ODI2OC4yOTcuMS4xNjY4MTY1NDc3LjAuMC4w) interface. The [GridColumnBase.FormatProvider](https://help.syncfusion.com/cr/windowsforms/Syncfusion.WinForms.DataGrid.GridColumnBase.html?_ga=2.154793776.967019853.1668146580-766490130.1650530957&_gl=1*kfpypb*_ga*NzY2NDkwMTMwLjE2NTA1MzA5NTc.*_ga_WC4JKKPHH0*MTY2ODE1ODI2OC4yOTcuMS4xNjY4MTY1NDc3LjAuMC4w#Syncfusion_WinForms_DataGrid_GridColumnBase_FormatProvider) property can be used to set custom format for the columns.

```
sfDataGrid1.Columns["Value"].Format = "00,00%";
sfDataGrid1.Columns["Value"].FormatProvider = new CustomFormatter();public class CustomFormatter : IDataGridFormatProvider
{
public object Format(string format, GridColumnBase gridColumn, object record, object value)
{
if (value == null)
{
throw new ArgumentNullException((value == null) ? "format" : "args");
}

if (gridColumn is GridColumn && (gridColumn as GridColumn).MappingName == "Value")
{
var orderInfo = record as OrderInfo;
return (Convert.ToDecimal((orderInfo.Value.ToString()))).ToString("0.00%");
}
return value.ToString();
}
public object GetFormat(Type formatType)
{
return this;
}
public string Format(string format, object arg, IFormatProvider formatProvider)
{
throw new NotImplementedException();
}
}
```