Skip to content

Commit de4e51e

Browse files
How to bind the list of string to WPF DataGrid(SfDataGrid)?
How to bind the list of string to WPF DataGrid(SfDataGrid)?
1 parent 3074575 commit de4e51e

File tree

1 file changed

+50
-2
lines changed

1 file changed

+50
-2
lines changed

README.md

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,50 @@
1-
# how-to-bind-the-list-of-string-to-wpf-data-grid
2-
How to bind the list of string to WPF DataGrid(SfDataGrid)?
1+
# How to bind the list of string to WPF DataGrid(SfDataGrid)?
2+
3+
## About the sample
4+
5+
This example illustrates how to bind the list of string to WPF DataGrid
6+
7+
By default, SfDataGrid is bound to a collection with a class type. You can bind a list of string as an ItemsSource of SfDataGrid can be achieved by using GridTemplateColumn.
8+
9+
```c#
10+
public class ViewModel
11+
{
12+
public ViewModel()
13+
{
14+
this.DataFieldList = new List<string>() { "Item1", "Item2" , "Item3", "Item4", "Item5", "Item6", "Item7", "Item8", "Item9", "Item10" };
15+
}
16+
17+
public List<string> DataFieldList
18+
{
19+
get;
20+
set;
21+
}
22+
}
23+
```
24+
```xml
25+
<Window.DataContext>
26+
<local:ViewModel />
27+
</Window.DataContext>
28+
<Grid>
29+
<syncfusion:SfDataGrid Name="dataGrid"
30+
AllowFiltering="False"
31+
AllowResizingColumns="False"
32+
AutoGenerateColumns="False"
33+
ColumnSizer="Star"
34+
NavigationMode="Row"
35+
ItemsSource="{Binding DataFieldList, UpdateSourceTrigger=PropertyChanged}">
36+
<syncfusion:SfDataGrid.Columns>
37+
<syncfusion:GridTemplateColumn HeaderText="Column Name" >
38+
<syncfusion:GridTemplateColumn.CellTemplate>
39+
<DataTemplate>
40+
<TextBlock Text="{Binding}" />
41+
</DataTemplate>
42+
</syncfusion:GridTemplateColumn.CellTemplate>
43+
</syncfusion:GridTemplateColumn>
44+
</syncfusion:SfDataGrid.Columns>
45+
</syncfusion:SfDataGrid>
46+
</Grid>
47+
```
48+
49+
## Requirements to run the demo
50+
Visual Studio 2015 and above versions

0 commit comments

Comments
 (0)